undefined reference to gzdopen, gzclose, gzread

一曲冷凌霜 提交于 2019-12-12 04:45:12

问题


I have compiled and installed the 2.2.7.2 version of libxml. While compiling, I have this error: Makefile:755: recipe for target 'install-data-local' failed. But the lib files are correctly generated (libxml2.a and libxml2.so). I'd like to use libxml2 in a C project so I edited my makefiles in order to integrate lib files (libxml2.a and libxml2.so). The problem is that when I compile my project I get the followings errors: /libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzdopen' /libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzclose' /libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzread' ...etc It seems that I have to install the zlib library in order to resolve this linker errors. I installed the zlib library and edited the LD_LIBRARY_PATH in order to add the path where are the zlib libraries. I recompiled my project, but I still always having the same linker errors.

Would you please help me to resolve those linker errors.

Regards.


回答1:


See the libxml2 FAQ:

Troubles compiling or linking programs using libxml2

Usually the problem comes from the fact that the compiler doesn't get the right compilation or linking flags. There is a small shell script xml2-config which is installed as part of libxml2 usual install process which provides those flags. Use

xml2-config --cflags

to get the compilation flags and

xml2-config --libs

to get the linker flags. Usually this is done directly from the Makefile as:

CFLAGS=`xml2-config --cflags`

LIBS=`xml2-config --libs`

On my current system, the output from xml2-config --libs is

-lxml2 -lz -lpthread -licucore -lm


来源:https://stackoverflow.com/questions/41898192/undefined-reference-to-gzdopen-gzclose-gzread

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