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

Why and how to fix it?

+6
unresolved-external libpng
source share
2 answers

The library has been modified to better hide internal structures. So what you need to do is:

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 execute LoadLibrary, do the following:

 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 calls an unresolved external, will now work fine:

 if (setjmp(png_jmpbuf(png_ptr))) { 

I posted it here since I could not find another place. I was looking for a problem and found that other people are facing the same problem, but without a solution, so they again switched to an earlier version of libpng. So I thought I'd post it here.

+9
source share

Another solution would be to not load libpng dynamically, but to reference it statically, in which case an additional method is not needed. But this requires a library, and libpng will always be loaded, not just when necessary.

+6
source share

All Articles