问题
I'm using this in my makefile to build my program:
all: server.cpp
g++ -o server server.cpp -I ~/boost/include -L~/boost/lib -Wl,-rpath,~/boost/lib -lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1
When I compile I get these warnings:
/usr/bin/ld: warning: libboost_system.so.1.53.0, needed by /usr/local/lib/libboost_thread.so, may conflict with libboost_system.so.5
When I run my program I receive the warning :
./server: error while loading shared libraries: libboost_thread.so.1.53.0: cannot open shared object file: No such file or directory
the -Wl/rpath command is not working for me at the moment. I have also tired using
export LD_LIBRARY_PATH=~/boost/lib
before I run my program and I get this back from the terminal:
export: relocation error: export: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
What can I do to specify what library I want to use when I execute the program?
回答1:
The libraries are (usually) boost/lib/stage/lib
, not boost/lib
.
Also the dynamic loader does not support ~
expansion. Use the fully qualified path, e.g.
-Wl,-rpath,/home/hededo/boost/stage/lib
Or, indeed, as I showed in my previous answer
-Wl,-rpath,"$HOME/boost/stage/lib"
The quotes are just to make it work if $HOME
contains special characters (like whitespace)
You can also look at
- static linking - so you can use Boost but never rely on any external shared library for it
- the BCP utility is a tool for extracting subsets of Boost (here: bcp)
回答2:
Alternatively you can use the non-boost asio which doesn't require linking with boost.
来源:https://stackoverflow.com/questions/22902979/linking-boost-1-55-0-asio