卡在:编译 qtbase/src/gui/image/qpnghandler.cpp时报错:
.obj/qpnghandler.o: In function `QPngHandlerPrivate::readPngHeader()':
qpnghandler.cpp:(.text+0xbe2): undefined reference to `png_set_longjmp_fn'
.obj/qpnghandler.o: In function `QPNGImageWriter::writeImage(QImage const&, int, QString const&, int, int)':
qpnghandler.cpp:(.text+0x273b): undefined reference to `png_set_longjmp_fn'
.obj/qpnghandler.o: In function `QPngHandlerPrivate::readPngImage(QImage*)':
qpnghandler.cpp:(.text+0x30cc): undefined reference to `png_set_longjmp_fn'
collect2: ld returned 1 exit status
我以为是没有加-lpng库,在Makefile中添加了 -lpng,结果还是没能解决。
打开qtbase/src/gui/image/qpnghandler.cpp文件:
#if PNG_LIBPNG_VER >= 10400 && PNG_LIBPNG_VER <= 10502 \
&& defined(PNG_PEDANTIC_WARNINGS_SUPPORTED)
/*
Versions 1.4.0 to 1.5.2 of libpng declare png_longjmp_ptr to
have a noreturn attribute if PNG_PEDANTIC_WARNINGS_SUPPORTED
is enabled, but most declarations of longjmp in the wild do
not add this attribute. This causes problems when the png_jmpbuf
macro expands to calling png_set_longjmp_fn with a mismatched
longjmp, as compilers such as Clang will treat this as an error.
To work around this we override the png_jmpbuf macro to cast
longjmp to a png_longjmp_ptr.
*/
# undef png_jmpbuf
# ifdef PNG_SETJMP_SUPPORTED
# define png_jmpbuf(png_ptr) \
(*png_set_longjmp_fn((png_ptr), (png_longjmp_ptr)longjmp, sizeof(jmp_buf)))
# else
# define png_jmpbuf(png_ptr) \
(LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
# endif
#endif
这该怎么处理呀?
如下为调用到 png_jmpbuf 的地方:
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
png_ptr = 0;
amp.deallocate();
state = Error;
return false;
}