Search code examples
c++linuxunixstatic-librariesxerces-c

Statically linked xerces 3.0.0 does not work while dynamic works on Linux


So I am trying to statically link Xerces 3.0.0 on linux.

I did it already with dynamic link and it works, but in order to avoid dependancy I want to do it statically.

I changed all of the make files to do it in appropriate way

-Wl,-Bstatic ... -lxerces-c -Wl,-Bdynamic ...

But I am getting following errors:

  undefined reference to '__ctype_b'
  undefined reference to '__ctype_tolower'
  undefined reference to '__ctype_toupper'

I fixed those with brute force method found here

But there was another type of errors related to xerces.

Xerces/3.0.0/lib/libxerces-c.a(PosixMutexMgr.o): 
In function `xercesc_3_0::PosixMutexMgr::create(xercesc_3_0::MemoryManager*)':

PosixMutexMgr.cpp:(.text+0x84): undefined reference to `pthread_mutexattr_init'
PosixMutexMgr.cpp:(.text+0x95): undefined reference to `pthread_mutexattr_settype'
PosixMutexMgr.cpp:(.text+0xad): undefined reference to `pthread_mutexattr_destroy'
PosixMutexMgr.cpp:(.text+0xd0): undefined reference to `pthread_mutexattr_destroy'

It seems like its missing pthread so I tried adding it but that does not fix the problem... These errors are coming from Xerces ...and dynamic version works fine static one is failing.

Any ideas???

Thanks


Solution

  • The dynamic version of the xerces will have dependencies on libpthread that ensure the loader will pick up the correct library.

    Specifying libphtread on your linker command line should fix those unresolved externals, did you (a) put in in the right place on the command line as the ordering matters and (b) did you try the both the static and dynamic versions of libpthread?