Linking erros xerces-c on GNAT

I have to use a C++ library that uses xerces-c. Then I have an Ada project that imports two symbols from the previously mentioned C++ library. When I try to build the main of the Ada project, a bunch of undefined references arises, so I suppose I'm not linking correctly to xerces-c. I've ensured y have the libxerces-c.a and the headers in my path (I'm using CentOS).

This is the package Linker I'm using in my gpr, which I found by googling post of people having similar link errors:

package Linker is
  for Linker_Options use ("-Wl", "-Bstatic", "-lxerces-c", "-Wl", "-Bdynamic");
end Linker;

This is an example of one of the linking erros: undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)'

I'm solving the problems for now by creating a gpr library project for xerces-c with for Externally_Built use "True"; and placing the libxerces-c.a manually in the lib directory of that project, but it really sounds weird to me. This way the linking erros disappear and everything seems to work.

Has anybody faced similar problems?


  • My first thought would be to mention the .a library directly:

    package Linker is
       for Switches ("ada") use ("/where/ever/libxerxes-c.a");
    end Linker;

    (a default Ada link calls in libgnat.a like this).

    Some linkers need to see the callers of a static library before they see the library; you can use -Wl,-v to see what the arguments actually passed to the linker are. Your scheme of putting the xerxes-c library in an externally-built GPR may well affect the order of linker arguments.