|
Boost Users : |
Subject: [Boost-users] Problems linking statically under linux
From: Vial, Florent (fvial_at_[hidden])
Date: 2010-05-19 05:02:55
Hi all,
I recently need to link my application statically to the boost
libraries.
I am on a RHEL 5.3 (x86_64) system and compiling/linking with gcc 4.1.2.
I built my boost 1.43.0 static libraries using follwing command line:
./bjam --build-dir="/tmp/boost_143.gcc41" threading=multi link=static
runtime-link=static --prefix="/usr/local/boost1430-gcc41" --without-mpi
--without-python --without-serialization --without-test --without-wave
address-model=64 -d+2 --layout=tagged cxxflags="-fPIC -pipe
-march=nocona -msse2 -pthread -Wno-multichar -DLINUX"
My tools/build/v2/user-config.jam contains only
using gcc ;
I'll just take the example of the thread library for describing my
problem.
I can see that the all the wished libraries built fine, with a typical
compile line being:
"g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall
-pthread -m64 -fPIC -pipe -march=nocona -msse2 -pthread -Wno-multichar
-DLINUX -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_LIB=1
-DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o
"/tmp/boost_143.build.gcc41/boost/bin.v2/libs/thread/build/gcc-4.1.2/rel
ease/address-model-64/link-static/runtime-link-static/threading-multi/pt
hread/thread.o" "libs/thread/src/pthread/thread.cpp"
When i "su" and add "install" to the bjam command line above, all files
install properly and /usr/local/boost1430-gcc41/lib is populated with
static libraries like libboost_thread-mt-s.a
Now i build my library that uses the boost thread library. A typical
compile line is :
/usr/bin/g++ -Wall -g -O3 -g -g -pipe -march=nocona -msse2 -pthread
-Wno-multichar -DLINUX -fPIC -pthread -c -o obj/myfile.o myfile.cpp
-I../include -I./ -I/usr/local/boost1430-gcc41/include/boost-1_43
-I/usr/local/cppunit1121-gcc41/include -I../include/mylib
AR ../lib/libmylib.a
Now i try to build the unit test for that library using :
ar -rsc ../lib/libmylib.a obj/myfile.o
LD /home/florent/dev/mylib/MylibTestMain
/usr/bin/g++ -o /home/florent/dev/mylib/MylibTestMain
obj/MylibTestMain.o obj/AUnitTest.o obj/AnotherUnitTest.o -L../lib
-lmylib -L/usr/local/cppunit1121-gcc41/lib -lcppunit -ldl
-L/usr/local/lib64 -L/usr/local/boost1430-gcc41/lib -lboost_thread-mt-s
And i get a lot of undefined references:
obj/AUnitTest.o: In function `AUnitTest::testAFunction()':
undefined reference to `boost::thread_group::thread_group()'
undefined reference to `boost::thread_group::join_all()'
undefined reference to `boost::thread_group::~thread_group()'
undefined reference to `boost::mutex::~mutex()'
...
<snip>
So my question is: how do i link properly statically with the boost
libraries ? Is there any defined that i should be aware of while
compiling my unit tests ?
Thank you in advance,
Florent
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Munchen - Registergericht: Amtsgericht Munchen - Handelsregisternummer: HRA 57918
Personlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Munchen - Registergericht: Amtsgericht Munchen - Handelsregisternummer: HRB 54477
Geschaftsfuhrer: Franz Kraus; Dr. Martin Prillmann
A new star is born - ALEXA the most versatile digital camera system.
Get all the latest information from arridigital.com and YouTube.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net