g++编译c++11特性 的.cc文件
生活随笔
收集整理的這篇文章主要介紹了
g++编译c++11特性 的.cc文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
寫一個.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++即可。
更換g++編譯器,并加入-std=c++11參數
執行如下命令 g++ -std=c++11 test_lock.cc -o test_lock
運行時出現如下錯誤,原因時編譯時并未支持多線程特性,這里需要在編譯過程中加入
[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
執行如下命令即可
g++ -std=c++11 test_lock.cc -o test_lock -lpthread
總結
以上是生活随笔為你收集整理的g++编译c++11特性 的.cc文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个圣经中好听的名字。
- 下一篇: 绝区零网页活动丁尼用途介绍