首页 > 代码库 > g++4.8.2的thread问题

g++4.8.2的thread问题

c++11支持多线程,底层还是使用的lphtread,所以编译的时候需要加上相关的一些参数。

下面是我使用codeblokcs编译成功的例子

第一行是编译参数  需要 -std=c++11  lpthread

第二行是链接参数   需要 -Wl,--no-as-needed  -lpthread


-------------- Build: Debug in thread (compiler: GNU GCC Compiler)---------------

g++ -Wall -fexceptions -g -std=c++11 -lpthread -lphtread -I/usr/local/include/boost -c /root/codewok/thread/main.cpp -o obj/Debug/main.o
g++ -L/usr/local/lib -o bin/Debug/thread obj/Debug/main.o  -Wl,--no-as-needed -lboost_system -lboost_thread -lpthread  
Output file is bin/Debug/thread with size 107.79 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

-------------- Run: Debug in thread (compiler: GNU GCC Compiler)---------------

Checking for existence: /root/codewok/thread/bin/Debug/thread
Executing: gnome-terminal --disable-factory -t thread -x  /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /root/codewok/thread/bin/Debug/thread  (in /root/codewok/thread/.)
Process terminated with status 0 (0 minute(s), 1 second(s))