c++11支持多線程,底層仍是使用的lphtread,因此編譯的時候須要加上相關的一些參數。c++
下面是我使用codeblokcs編譯成功的例子多線程
第一行是編譯參數 須要 -std=c++11 lpthread
ui
第二行是連接參數 須要 -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))
c++11