简体   繁体   中英

How do compile a simple program using boost::thread in cygwin?

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()'
...
...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM