如何在 cygwin 中使用 boost::thread 编译一个简单的程序?
我从 cygwin 安装了 boost 包,并有一个目录 /usr/include/boost ,其中包含一堆 *.hpp 文件,包括 thread.hpp,我需要通过
#include <boost/thread.hpp>
几个 *.a 文件 将其包含在 c++ 文件中似乎与 boost::thread 有关。
$ ls /usr/lib/libboost_thread* -1
/usr/lib/libboost_thread-gcc-mt-1_33_1.a
/usr/lib/libboost_thread-gcc-mt.a
/usr/lib/libboost_thread-mt.a
/usr/lib/libboost_thread-mt.dll.a
我的 g++ 编译命令应该是什么样子?我知道我应该使用 -L -I 和 -l 的某种组合,但我不确定为每个参数提供什么,到目前为止没有任何效果对我有用。
我已经尝试过以下方法:
$ g++ test.cpp -lboost_thread-gcc-mt
/cygdrive/c/Users/jonderry/AppData/Local/Temp/ccaNCMaA.o:test.cpp:(.text$_ZN5boost6detail11thread_dataIPFvvEED
0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thre
ad_data_base::~thread_data_base()'
...
...
I installed the boost package from cygwin and have a directory /usr/include/boost that includes a bunch of *.hpp files, including thread.hpp, which I need to include in the c++ file, via
#include <boost/thread.hpp>
Also, several *.a files seem to be related to boost::thread.
$ ls /usr/lib/libboost_thread* -1
/usr/lib/libboost_thread-gcc-mt-1_33_1.a
/usr/lib/libboost_thread-gcc-mt.a
/usr/lib/libboost_thread-mt.a
/usr/lib/libboost_thread-mt.dll.a
What should my g++ compilation command look like? I understand I should be using some combination of -L -I, and -l, but I'm not sure what to supply for each argument, and nothing is working for me so far.
I have tried the following:
$ g++ test.cpp -lboost_thread-gcc-mt
/cygdrive/c/Users/jonderry/AppData/Local/Temp/ccaNCMaA.o:test.cpp:(.text$_ZN5boost6detail11thread_dataIPFvvEED
0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thre
ad_data_base::~thread_data_base()'
...
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑(删除-gcc部分):
g++sample.cpp -lboost_thread-mt
。您可能还需要添加-lpthread
或-pthread
。如果仍然没有成功,请发布您收到的错误。华泰EDIT (removed -gcc part):
g++ sample.cpp -lboost_thread-mt
. You may need to add-lpthread
or-pthread
as well. If still no luck, please post the errors you get. HTH