Tom
Tom

Reputation: 45104

xerces-c 2.8 : error while loading shared libraries

I'm trying to compile a program running on an HP UX server on a Red Hat Linux.

It uses xerces-c library to parse xml files. Compilation is ok, but when i try to run it, I get the following message

./a.out: error while loading shared libraries: libxerces-c.so.28: cannot open shared object file: No such file or directory

I wrote a very simple program to try and understand whats going on:

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/TransService.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>



int main(int argc, char* argv[])
{
        return 0;
}

And compiled it like this:

g++ test.cpp -L./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include

Surprisingly the file is actually there:

lib]$ ls
libxerces-c.a   libxerces-c.so.28    libxerces-depdom.a   libxerces-depdom.so.28
libxerces-c.so  libxerces-c.so.28.0  libxerces-depdom.so  libxerces-depdom.so.28.0

Any thoughts ? I feel i'm missing something, but don't know what.

Thanks in advance.

Upvotes: 2

Views: 5709

Answers (3)

IanNorton
IanNorton

Reputation: 7282

You need to tell the runtime c library where to find the various symbols that arent compiled statically in your code and arent in the usualy /lib and /usr/lib locations.

You do this by adding the path to your shared library to LD_LIBRARY_PATH. In this case, this will be what you have been putting for the -L argument to the compiler.

Upvotes: 0

Nadir SOUALEM
Nadir SOUALEM

Reputation: 3519

the good way to do what you want is the following one:

g++ test.cpp -Xlinker -R ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include

or

g++ test.cpp -Wl,-rpath ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include

Xlinker or Wl options allow you to use specific linking options, you do not need to modifiy LD_LIBRARY_PATH

Upvotes: 0

catwalk
catwalk

Reputation: 6476

run ldd a.out and see if the linker can resolve the right .so file

export LD_LIBRARY_PATH to include the current folder (in the same manner as the PATH variable) and check ldd again

Upvotes: 6

Related Questions