Re: [Boost-users] [Boost.Asio] tutorial #1 code does not compile (g++)
Okay, so I have made a bit of progress. After building Boost.Asio with: b2 --with-system --with-thread --with-date_time --with-regex --with-serialization stage , and building Boost.Chrono with (replacing bjam with b2): bjam libs/chrono/build The code is now compiling with the following g++ command: g++ -v -Wall -L ${BOOST_ROOT}/stage/lib -L ${BOOST_ROOT}/bin.v2/libs/chrono/build/clang-darwin-11.0/debug/threading-multi/visibility-hidden -lboost_chrono -lboost_date_time -lboost_system -I. -I${BOOST_ROOT} -o main main.cpp However, when I go to run main, the program crashes with the following message: dyld: Library not loaded: @rpath/libboost_chrono.dylib Referenced from: /Users/ajm/Projects/boost-threads/ex1/./main Reason: image not found Abort trap: 6 I suspect that there is something wrong with the Boost.Chrono dynamic library file that was built (probably because of how I built it), but I am not sure what it would be. Any suggestions? Thanks, *Andrew J. E. McFarlane*
On 1/30/2020 5:35 PM, Andrew McFarlane via Boost-users wrote:
Okay, so I have made a bit of progress. After building Boost.Asio with:
b2 --with-system --with-thread --with-date_time --with-regex --with-serialization stage
, and building Boost.Chrono with (replacing bjam with b2):
bjam libs/chrono/build
The code is now compiling with the following g++ command:
g++ -v -Wall -L ${BOOST_ROOT}/stage/lib -L ${BOOST_ROOT}/bin.v2/libs/chrono/build/clang-darwin-11.0/debug/threading-multi/visibility-hidden -lboost_chrono -lboost_date_time -lboost_system -I. -I${BOOST_ROOT} -o main main.cpp
/ / However, when I go to run main, the program crashes with the following message:
dyld: Library not loaded: @rpath/libboost_chrono.dylib
Referenced from: /Users/ajm/Projects/boost-threads/ex1/./main
Reason: image not found
Abort trap: 6
/ / I suspect that there is something wrong with the Boost.Chrono dynamic library file that was built (probably because of how I built it), but I am not sure what it would be. Any suggestions?
Lookup RPATH for Linux.
On 31/01/2020 11:35, Andrew McFarlane wrote:
Okay, so I have made a bit of progress. After building Boost.Asio with:
b2 --with-system --with-thread --with-date_time --with-regex --with-serialization stage
, and building Boost.Chrono with (replacing bjam with b2):
bjam libs/chrono/build
You could have just added --with-chrono to the first command.
The code is now compiling with the following g++ command:
g++ -v -Wall -L ${BOOST_ROOT}/stage/lib -L ${BOOST_ROOT}/bin.v2/libs/chrono/build/clang-darwin-11.0/debug/threading-multi/visibility-hidden -lboost_chrono -lboost_date_time -lboost_system -I. -I${BOOST_ROOT} -o main main.cpp
You should not link with libs directly in bin.v2; use the stage/lib directory instead. (They're not different, it's just that the bin.v2 path is fragile.)
However, when I go to run main, the program crashes with the following message:
dyld: Library not loaded: @rpath/libboost_chrono.dylib
Referenced from: /Users/ajm/Projects/boost-threads/ex1/./main
Reason: image not found
Abort trap: 6
You either need to tell your compiler to use the static libraries (it usually defaults to using dynamic libraries), or you need to set the RPATH at compile time to the (absolute path of the) stage/lib folder, or the LD_LIBRARY_PATH when you run the app (less preferred). Or use the system-provided libraries instead, which will Just Work™ without any of this.
participants (3)
-
Andrew McFarlane
-
Edward Diener
-
Gavin Lambert