Skip to content

[已解決] warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

Last Updated on 2021-09-18 by Clay

問題描述

今天我在 Mac OS 上撰寫程式的時候,突然發現有些舊程式(之前是在 Windows 作業系統上編譯的)在編譯時會跑出以下警吿:

warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

在某些任務中甚至讓編譯直接失敗。查詢了之後發現無法直接改設定讓其生效,需要在編譯時加入 -std=c++11 的參數,於是我決定直接改動 ~/.bash_profile 設定檔。(如果你是其他腳本語言,就與之改動相對應的設定檔)


解決方法

在 Terminal 中輸入以下指令:

echo 'alias g++="g++ -std=c++11"' >> ~/.bash_profile
source ~/.bash_profile

這樣一來,以後使用 g++ 編譯時就會自帶 -std=c++11 參數了。試著編譯看看,原先有著的警告訊息應該消失了。


References


Read More

Tags:

Leave a Reply