Error while linking program to boost thread library
I had to build boost library for threading. So I gave the command
./bootstrap.sh
in the boost_1_46_1 directory. Then
bjam --toolset=gcc --build-type=complete --with-thread link=static stage
When I tried to compile a simple program involving开发者_运维技巧 threads, using the command below, I get errors.
g++ -I/home/sharatds/Downloads/boost_1_46_1 /home/sharatds/Downloads/boost_1_46_1/stage/lib/libboost_thread.a main.cpp -o ini
main.cpp:(.text+0x804): undefined reference to `boost::thread::join()'
main.cpp:(.text+0x9ec): undefined reference to `boost::thread::~thread()'
Am I missing something ?
I think that your build command is malformed. You are explicitly listing an archive library in an unusual way, and I think GCC is ignoring or misinterpreting it.
Try separating your build into two steps. One step to compile your .cpp file to a .o, and then another to link the .o with the boost_thread archive library and emit an executable.
g++ -I/home/sharatds/Downloads/boost_1_46_1 main.cpp -o main.o
g++ main -o ini -L/home/sharatds/Downloads/boost_1_46_1/stage/lib/ -lboost_thread
The first line above compiles your main.cpp into an object file. The second line links your object file with the boost_thread library. The -L argument acts much like the -I argument, but provides a search path for libraries, rather than include files.
Also, I suspect that your argument to -I should actually be
-I/home/sharatds/Downloads/boost_1_46_1/stage/include
so that you are including the headers from the build results, rather than from the source tree itself. Just guessing on that one though.
精彩评论