Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't link with Xerces-c static library with g++
    text
    copied!<p>I downloaded and unpacked <code>xerces-c-3.1.1-x86_64-linux-gcc-3.4.tar.gz</code>, So I have </p> <pre><code>$ 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 </code></pre> <p>Then I have my <code>Makefile</code> as </p> <pre><code>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 </code></pre> <p>The <code>make</code> command works fine.</p> <pre><code>$ 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 </code></pre> <p>But the result executable <code>ReadXML</code> is not as "static" as I hope it to be. It prints </p> <pre><code>./ReadXML: error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory </code></pre> <p>until I <code>setenv LD_LIBRARY_PATH /users/jdyu/labs/xerces/xerces-c-3.1.1-x86_64-linux-gcc-3.4/lib</code>. Obviously, the xerces-c is linked dynamically.</p> <p>Why the <code>-Bstatic</code> doesn't help me to create a static linked executable?</p> <hr> <p>Update 2013.05.13</p> <p>Followed @n.m. 's advise and got error like</p> <pre><code> 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 </code></pre> <p>And with <code>LDFLAGS += -Wl,-Bstatic -lxerces-c -Wl,-Bdynamic</code>, I got</p> <pre><code>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 to `xercesc_3_1::DOMImplementationRegistry::getDOMImplementation(unsigned short const*)' DOM.cpp:(.text+0x3b3): undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager' DOM.cpp:(.text+0x3dc): undefined reference to `xercesc_3_1::XMLUni::fgXercesHandleMultipleImports' DOM.cpp:(.text+0x3f0): undefined reference to `xercesc_3_1::XMLUni::fgXercesSchema' DOM.cpp:(.text+0x404): undefined reference to `xercesc_3_1::XMLUni::fgXercesSchemaFullChecking' DOM.cpp:(.text+0x42f): undefined reference to `xercesc_3_1::XMLUni::fgDOMErrorHandler' ... # Many other lines ReadXML.cpp:(.text+0x1eb): undefined reference to `xercesc_3_1::XMLString::release(char**, xercesc_3_1::MemoryManager*)' ReadXML.o:(.gcc_except_table+0x28): undefined reference to `typeinfo for xercesc_3_1::XMLException' collect2: ld returned 1 exit status make: *** [ReadXML] Error 1 </code></pre> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload