expat undefined reference to `XML_SetElementHandler'
Asked Answered
K

1

3

I am getting these linker errors when i build my program using expat xml library .

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'

build instruction :

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

library is there on filesystem:

$ locate 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

Ran strace to check if any obvious issue :

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

when everything loaded properly why linker throws these errors , any idea ?

I can lookup the function in symbol table:-

$ nm -DC /usr/lib/x86_64-linux-gnu/libexpat.so |grep XML_SetElementHandler 
000000000000d4a0 T XML_SetElementHandler
Kizzykjersti answered 9/5, 2017 at 5:56 Comment(0)
N
3

See gcc newly installed libraries (libexpat1-dev) not recognised in current terminal (debian). Basically, on the g++ command line, move your source file before the expat library... something like

g++ -v node.cpp -L /usr/lib/x86_64-linux-gnu -lexpat
Nihi answered 9/5, 2017 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.