Last Updated on 2021-09-18 by Clay
Problem
Today when I was programming on Mac OS, I found some old programs would issue the following warning when compiling:
warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
In some tasks, even the compilation fails directly. After searching, I found that I couldn’t directly change the settings to make it take effect. I needed to add the -std=c++11
parameter when compiling, so I decided to change the ~/.bash_profile configuration file.
If you used another scripting language, change the corresponding configuration file.
Solution
Enter the following command in terminal:
echo 'alias g++="g++ -std=c++11"' >> ~/.bash_profile
source ~/.bash_profile
In this way, the -std=c++11
parameter will be included when compiling with g++ in the future. Try to compile and see, the original warning message should disappear.
References
- https://stackoverflow.com/questions/36962475/warning-auto-type-specifier-is-a-c11-extension-wc11-extensions
- https://stackoverflow.com/questions/39022787/error-non-aggregate-type-vectorint-cannot-be-initialized-with-an-initialize
Thank you so much!!!