Unresolved external png_set_longjmp_fn in libpng

≯℡__Kan透↙ 提交于 2019-12-23 09:34:10

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5190554/unresolved-external-png-set-longjmp-fn-in-libpng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!