Undefined Initial error when linking to a static library

I am trying to compile a project that depends on Xerces XML Parser . The project compiles for Windows without any difficulty, but I had problems compiling it with g ++ in Cygwin.

To use Xerces, I am trying to compile my code with the libxerces-ca static library. But when I do this, I get errors that look like this:

 /tmp/cc2QGvMh.o:test.cpp:(.text+0x3a): undefined reference to `xercesc_2_8::DOMImplementationRegistry::getDOMImplementation(unsigned short const*)' 

I checked the static library with ar and confirmed that it contains the DOMImplementationRegistry.o file, which defines the function that I am calling.

 ar -t libxerces-ca ... DOMImplementationImpl.o DOMImplementationRegistry.o DOMLocatorImpl.o ... 

I also extracted the object files from the library and used "nm" to make sure that the function actually being called by me exists:

 ar -x libxerces-ca nm --demangle DOMImplementationRegistry.o ... 00000080 T xercesc_2_8::getDOMImplSrcVectorMutex() 00000300 T xercesc_2_8::DOMImplementationRegistry::getDOMImplementation(unsigned short const*) 000002a0 T xercesc_2_8::DOMImplementationRegistry::addSource(xercesc_2_8::DOMImplementationSource*) ... 

Since I can compile everything for Windows, but not with g ++, I thought the error might be in the linker order (similar to the problem described in this question ), However, even after changing the linker order, I still get the same compiler error. I tried both

 g++ -o test.exe test.cpp -Llib -lxerces-c 

and

 g++ -o test.exe test.cpp lib/libxerces-ca 

Any ideas?

+4
source share
3 answers

You did not say the source of the archive. If it is not compiled with cygwin, this could be a name change problem. Compiling the library from the source may very well fix this.

It may also be that the archive is not built correctly, so it has problems with internal resolution. Try to name the library twice.

 g++ -o test.exe test.cpp lib/libxerces-ca lib/libxerces-ca 

If this works, the archive is broken and you must search or create a new one.

+4
source

Your project uses a method from the xercesc_2_6 namespace as indicated by the compiler error message, but your library offers a version of xercesc_2_8. The problem is probably caused by a mismatch between the headers you are using and the library object file.

+7
source

Try the linker option --enable-stdcall-fixup (see "man ld"). He will take care of naming conventions and calls:

 g++ -o test.exe test.o -Wl,--enable-stdcall-fixup -Llib -lxerces-c 
+1
source

All Articles