I've been pulling my hair out trying to figure out how to compile my app with boost regex.
I've installed boost from source on centos 5.
g++ -lboost_regex -o my_app my_app.c $(mysql_config --libs --cflags)
It compiles without any errors, however when I execute it:
error while loading shared libraries: libboost_regex.so.1.46.1: cannot open shared object file: No开发者_运维知识库 such file or directory
The location of that file is:
/usr/local/lib/libboost_regex.so.1.46.1
Anyone experience the same issues?
Did you try LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH your_program
to make sure it knows where to find the shared object? You can set the path when you link by using -Wl,-R/usr/local/lib
.
EDIT: To be more clear, when you link your code the linker will embed an RPATH and RUNPATH into the binary. These values tell the runtime loader where to find required shared objects.
If you add -Wl,-R/usr/local/lib
to your link command that should cause it to embed that directory and always check it when loading your program.
Try this.
$ LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH
$ export LD_LIBRARY PATH
Now try and tell us what happens.
精彩评论