Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved external png_set_longjmp_fn in libpng

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?

like image 384
Kharina Tigerfish Avatar asked Mar 04 '11 06:03

Kharina Tigerfish


1 Answers

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.

like image 187
Kharina Tigerfish Avatar answered Oct 04 '22 03:10

Kharina Tigerfish