c++ - Can't link with Xerces-c static library with g++ -


i downloaded , unpacked xerces-c-3.1.1-x86_64-linux-gcc-3.4.tar.gz, have

$ ls -1 /users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib libxerces-c-3.1.so libxerces-c.a libxerces-c.la libxerces-c.so pkgconfig 

then have makefile

cc := gcc cxx := g++ cxxflags := -o3 ldflags := -o3  cxxflags += -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include cxxflags += -dxerces_static_library ldflags += -l/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib ldflags += -bstatic ldflags += -lxerces-c  readxml: dom.o mydomerrorhandler.o myxmlstring.o readxml.o  clean:     @rm -rvf *.o readxml 

the make command works fine.

$ make -b g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o readxml.o readxml.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o dom.o dom.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o mydomerrorhandler.o mydomerrorhandler.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o myxmlstring.o myxmlstring.cpp gcc -o3 -l/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib -bstatic -lxerces-c  readxml.o dom.o mydomerrorhandler.o myxmlstring.o   -o readxml 

but result executable readxml not "static" hope be. prints

./readxml: error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: no such file or directory 

until setenv ld_library_path /users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib. obviously, xerces-c linked dynamically.

why -bstatic doesn't me create static linked executable?


update 2013.05.13

followed @n.m. 's advise , got error like

 gcc -o3 -l/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib -wl,-bstatic -lxerces-c  readxml.o dom.o mydomerrorhandler.o myxmlstring.o   -o readxml /usr/bin/ld: cannot find -lgcc_s collect2: ld returned 1 exit status make: *** [readxml] error 1 

and ldflags += -wl,-bstatic -lxerces-c -wl,-bdynamic, got

g++ -o3 -l/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib -wl,-bstatic -lxerces-c -wl,-bdynamic -o readxml dom.o mydomerrorhandler.o myxmlstring.o readxml.o dom.o: in function `parsexmlfile(char const*)': dom.cpp:(.text+0x3a6): undefined reference `xercesc_3_1::domimplementationregistry::getdomimplementation(unsigned short const*)' dom.cpp:(.text+0x3b3): undefined reference `xercesc_3_1::xmlplatformutils::fgmemorymanager' dom.cpp:(.text+0x3dc): undefined reference `xercesc_3_1::xmluni::fgxerceshandlemultipleimports' dom.cpp:(.text+0x3f0): undefined reference `xercesc_3_1::xmluni::fgxercesschema' dom.cpp:(.text+0x404): undefined reference `xercesc_3_1::xmluni::fgxercesschemafullchecking' dom.cpp:(.text+0x42f): undefined reference `xercesc_3_1::xmluni::fgdomerrorhandler' ... # many other lines readxml.cpp:(.text+0x1eb): undefined reference `xercesc_3_1::xmlstring::release(char**, xercesc_3_1::memorymanager*)' readxml.o:(.gcc_except_table+0x28): undefined reference `typeinfo xercesc_3_1::xmlexception' collect2: ld returned 1 exit status make: *** [readxml] error 1 

thanks

thanks @n.m. 's help. got answer after studying little libtool. let me post answer here.

finally working makefile looks like

cc := gcc cxx := g++ ld := g++ cxxflags := -o3 ldflags := -o3  cxxflags += -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include cxxflags += -dxerces_static_library ldflags += -l/users/jdyu/labs/xerces/xerces-c-3.1.1/lib  readxml: dom.o mydomerrorhandler.o myxmlstring.o readxml.o     $(ld) $(ldflags) -o $@ $^ -wl,-bstatic -lxerces-c -wl,-bdynamic -lnsl -lpthread -lcurl test: readxml     ldd $(abspath $<)     $(abspath $<) /users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml 

and result comes

$ make -b readxml g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o dom.o dom.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o mydomerrorhandler.o mydomerrorhandler.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o myxmlstring.o myxmlstring.cpp g++ -o3 -i/users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/include -dxerces_static_library   -c -o readxml.o readxml.cpp g++ -o3 -l/users/jdyu/labs/xerces/xerces-c-3.1.1/lib -o readxml dom.o mydomerrorhandler.o myxmlstring.o readxml.o -wl,-bstatic -lxerces-c -wl,-bdynamic -lnsl -lpthread -lcurl 

and

$ make test ldd /users/jdyu/labs/xerces/readxml/readxml     linux-vdso.so.1 =>  (0x00007fff6fdd6000)     libnsl.so.1 => /lib64/libnsl.so.1 (0x0000003b5e200000)     libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b4ea00000)     libcurl.so.4 => /usr/lib64/libcurl.so.4 (0x0000003b5f200000)     libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003b54e00000)     libm.so.6 => /lib64/libm.so.6 (0x0000003b4e200000)     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b54200000)     libc.so.6 => /lib64/libc.so.6 (0x0000003b4de00000)     /lib64/ld-linux-x86-64.so.2 (0x0000003b4d600000)     libidn.so.11 => /lib64/libidn.so.11 (0x0000003b5d200000)     libldap-2.4.so.2 => /usr/lib64/libldap-2.4.so.2 (0x0000003b60000000)     librt.so.1 => /lib64/librt.so.1 (0x0000003b4f200000)     libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003b56a00000)     libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003b55e00000)     libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003b56600000)     libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003b55600000)     libz.so.1 => /lib64/libz.so.1 (0x0000003b4ee00000)     libssl3.so => /usr/lib64/libssl3.so (0x0000003b61000000)     libsmime3.so => /usr/lib64/libsmime3.so (0x0000003b60800000)     libnss3.so => /usr/lib64/libnss3.so (0x0000003b5ea00000)     libnssutil3.so => /usr/lib64/libnssutil3.so (0x0000003b60400000)     libplds4.so => /lib64/libplds4.so (0x0000003b5ca00000)     libplc4.so => /lib64/libplc4.so (0x0000003b5c600000)     libnspr4.so => /lib64/libnspr4.so (0x0000003b5e600000)     libdl.so.2 => /lib64/libdl.so.2 (0x0000003b4e600000)     libssh2.so.1 => /usr/lib64/libssh2.so.1 (0x0000003b5de00000)     liblber-2.4.so.2 => /usr/lib64/liblber-2.4.so.2 (0x0000003b5fc00000)     libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003b4fa00000)     libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x0000003b5f800000)     libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003b57a00000)     libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003b55200000)     libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003b55a00000)     libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003b56200000)     libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003b5d600000)     libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003b4f600000)     libfreebl3.so => /lib64/libfreebl3.so (0x0000003b5da00000) /users/jdyu/labs/xerces/readxml/readxml /users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml parsing xml file '/users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml' ... parsing finished in 1 millisecond(s). 37 nodes found. xml platform terminated successfully! 

the xerces-c linked statically.


and libtool can make more static. append make file

readxml_: dom.o mydomerrorhandler.o myxmlstring.o readxml.o     libtool --tag=cxx --mode=link $(ld) $(ldflags) -o $@ $^ -lxerces-c -lnsl -lpthread -lcurl test_: readxml_     -ldd $(abspath $<)     $(abspath $<) /users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml 

and got result

$ make readxml_ libtool --tag=cxx --mode=link g++ -o3 -l/users/jdyu/labs/xerces/xerces-c-3.1.1/lib -o readxml_ dom.o mydomerrorhandler.o myxmlstring.o readxml.o -lxerces-c -lnsl -lpthread -lcurl libtool: link: g++ -o3 -o .libs/readxml_ dom.o mydomerrorhandler.o myxmlstring.o readxml.o  -l/users/jdyu/labs/xerces/xerces-c-3.1.1/lib /users/jdyu/labs/xerces/xerces-c-3.1.1/lib/libxerces-c.so -lnsl -lpthread -lcurl -wl,-rpath -wl,/usr/local/lib 

and

$ make test_ ldd /users/jdyu/labs/xerces/readxml/readxml_     not dynamic executable make: [test_] error 1 (ignored) /users/jdyu/labs/xerces/readxml/readxml_ /users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml parsing xml file '/users/jdyu/labs/xerces/xerces-c-3.1.1/samples/data/personal.xml' ... parsing finished in 1 millisecond(s). 37 nodes found. xml platform terminated successfully! 

there far more in libtool learn me. tried hard reading libtool code, failed figure out how coverts temporary dynamic .libs/readxml_ final readxml_ totally static linked. anyway, answer of question found.

thanks again, @n.m.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -