When loading libpng.dll dynamically, after upgrading from libpng13.dll to version 1.5, the compiler started reporting this unresolved external: png_set_longjmp_fn
How come and how do I fix it?
The library was changed to hide internal structures better. So what you need to do is this:
typedef jmp_buf* (*png_set_longjmp_fnPtr)(png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size);
png_set_longjmp_fnPtr mypng_set_longjmp_fnPtr = 0;
Then when you dynamically do a LoadLibrary, do this:
mypng_set_longjmp_fnPtr = (png_set_longjmp_fnPtr) GetProcAddress(hpngdll, "png_set_longjmp_fn");
extern "C"
{
jmp_buf* png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)
{
if (mypng_set_longjmp_fnPtr)
{
return (*mypng_set_longjmp_fnPtr)(png_ptr, longjmp_fn, jmp_buf_size);
}
return 0;
}
}
The following code, which causes the unresolved external, will now work fine again:
if (setjmp(png_jmpbuf(png_ptr)))
{
I posted this here since I could find no other location. I Googled the problem and found other people running into the same problem but with no solution so they just downgraded to an older version of libpng again. So I thought I would post it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With