寫一個.cc檔案,其中抱哈
std::lock_guard
以及
std::thread
等c++11特性,開始使用
gcc
編譯,過程中出現如下問題
gcc test_lock.cc -o test_lock
This file requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options
顯然缺少C++11特性,同時使用
gcc
來編譯會出現很多
std::__throw_system_error(int)
未定義的引用的問題,因為編譯時候gcc和g++是一緻的,但是連結得時候g++需要連結c++的std模闆庫,但是gcc編譯器并沒有,是以會出現如上問題,此時更換編譯器為
g++
即可。
[zhanghuigui@localhost c++_practice]$ ./test_lock
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted