Unresolved external png_set_longjmp_fn in libpng

6.5k Views Asked by At

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?

2

There are 2 best solutions below

0
On

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.

1
On

Another solution would be to not load the libpng dynamically, but link against its statically, in which case the extra method is not necessary. But that requires the library and libpng will always be loaded rather than only when needed.