expat未定义引用XML_SetElementHandler

问题描述:

当我使用expat xml库构建我的程序时,出现这些链接器错误。expat未定义引用XML_SetElementHandler

3288 /tmp/ccFZziQa.o: In function `xml::node::load_xml(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': 
3289 node.cpp:(.text+0xdec): undefined reference to `XML_SetElementHandler' 
3290 node.cpp:(.text+0xe08): undefined reference to `XML_SetCharacterDataHandler' 
3291 node.cpp:(.text+0xe2c): undefined reference to `XML_SetUserData' 
3292 node.cpp:(.text+0xe72): undefined reference to `XML_Parse' 
3293 node.cpp:(.text+0xeaa): undefined reference to `XML_GetErrorCode' 
3294 node.cpp:(.text+0xeb1): undefined reference to `XML_ErrorString' 
3295 node.cpp:(.text+0xecb): undefined reference to `XML_GetCurrentLineNumber' 

编译指令:

g++ -v -L /usr/lib/x86_64-linux-gnu -lexpat node.cpp 

库是那里的文件系统:

$定位libexpat.so

/lib/x86_64-linux-gnu/libexpat.so.1 
/lib/x86_64-linux-gnu/libexpat.so.1.6.0 
/usr/lib/x86_64-linux-gnu/libexpat.so 

[R一个strace的,以检查是否有任何明显的问题:

2170 [pid 3361] open("/usr/include/expat.h", O_RDONLY|O_NOCTTY) = 4 

3172 [pid 3364] stat("/usr/lib/x86_64-linux-gnu/libexpat.so", {st_mode=S_IFREG|0644, st_size=166032, ...}) = 0 
3173 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 7 
3174 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 8 
3175 [pid 3364] stat("/tmp/ccFZziQa.o", {st_mode=S_IFREG|0600, st_size=89008, ...}) = 0 
3176 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 8 
3177 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 9 




3172 [pid 3364] stat("/usr/lib/x86_64-linux-gnu/libexpat.so", {st_mode=S_IFREG|0644, st_size=166032, ...}) = 0 
3173 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 7 
3174 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 8 
3175 [pid 3364] stat("/tmp/ccFZziQa.o", {st_mode=S_IFREG|0600, st_size=89008, ...}) = 0 
3176 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 8 
3177 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 9 

当一切正确加载,为什么连接抛出这些错误,任何想法?

我可以查找在符号表的功能: -

$ nm -DC /usr/lib/x86_64-linux-gnu/libexpat.so |grep XML_SetElementHandler 
000000000000d4a0 T XML_SetElementHandler 

gcc newly installed libraries (libexpat1-dev) not recognised in current terminal (debian)。基本上,在g ++命令行上,将源文件移到expat库之前...类似于

g++ -v node.cpp -L /usr/lib/x86_64-linux-gnu -lexpat