开发者

xerces-c 2.8 : error while loading shared libraries

开发者 https://www.devze.com 2022-12-11 09:47 出处:网络
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

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>
#i开发者_如何学运维nclude <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.


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消