c++ expat未定义的对“XML_SetElement”的引用

b1uwtaje  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(141)

我得到这些链接器错误时,我建立我的程序使用expat xml库。

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

字符串

构建指令:

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

库在文件系统上:

$ locate libexpat.so

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

运行strace检查是否存在任何明显问题:

  1. 2170 [pid 3361] open("/usr/include/expat.h", O_RDONLY|O_NOCTTY) = 4
  2. 3172 [pid 3364] stat("/usr/lib/x86_64-linux-gnu/libexpat.so", {st_mode=S_IFREG|0644, st_size=166032, ...}) = 0
  3. 3173 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 7
  4. 3174 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 8
  5. 3175 [pid 3364] stat("/tmp/ccFZziQa.o", {st_mode=S_IFREG|0600, st_size=89008, ...}) = 0
  6. 3176 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 8
  7. 3177 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 9
  8. 3172 [pid 3364] stat("/usr/lib/x86_64-linux-gnu/libexpat.so", {st_mode=S_IFREG|0644, st_size=166032, ...}) = 0
  9. 3173 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 7
  10. 3174 [pid 3364] open("/usr/lib/x86_64-linux-gnu/libexpat.so", O_RDONLY) = 8
  11. 3175 [pid 3364] stat("/tmp/ccFZziQa.o", {st_mode=S_IFREG|0600, st_size=89008, ...}) = 0
  12. 3176 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 8
  13. 3177 [pid 3364] open("/tmp/ccFZziQa.o", O_RDONLY) = 9


当一切都加载正常,为什么链接器抛出这些错误,任何想法?
我可以在符号表中查找函数:

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

biswetbf

biswetbf1#

基本上,在g++命令行上,将源文件移到expat库之前..

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

字符串

相关问题