undefined reference to gzdopen, gzclose, gzread

2019-09-13 00:33发布

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条回答
倾城 Initia
2楼-- · 2019-09-13 00:54

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
查看更多
登录 后发表回答