将程序链接到 boost 线程库时出错
我必须为线程构建 boost 库。 给出了命令
./bootstrap.sh
所以我在boost_1_46_1目录下 。然后,
bjam --toolset=gcc --build-type=complete --with-thread link=static stage
当我尝试使用下面的命令编译一个涉及线程的简单程序时,出现错误。
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()'
我错过了什么吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的构建命令格式错误。您以一种不寻常的方式明确列出了一个存档库,我认为 GCC 忽略或误解了它。
尝试将构建分为两个步骤。第一步将 .cpp 文件编译为 .o,然后另一步将 .o 与 boost_thread 存档库链接并发出可执行文件。
上面的第一行将 main.cpp 编译成目标文件。第二行将您的目标文件与 boost_thread 库链接。 -L 参数的作用与 -I 参数非常相似,但提供库的搜索路径,而不是包含文件。
另外,我怀疑您对 -I 的参数实际上应该是
-I/home/sharatds/Downloads/boost_1_46_1/stage/include
,以便您包含构建结果中的标头,而不是来自源树本身。不过只是猜测而已。
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.
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.