很多时候我们的机器上会安装多个版本的gcc,但默认的gcc并不一定指向我们想要的gcc版本。
如果gcc版本太低,会报错:
cc1plus: 错误:无法识别的命令行选项“-std=c++11”
cc1plus: 错误:无法识别的命令行选项“-std=c++11”
cc1plus: 错误:无法识别的命令行选项“-std=c++11”
如果版本太高,warning很可能会变成error,如:
third_party/boringssl/crypto/bio/file.c: In function ‘file_ctrl’:
third_party/boringssl/crypto/bio/file.c:186:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
num = 0;
~~~~^~~
third_party/boringssl/crypto/bio/file.c:187:5: note: here
case BIO_C_FILE_SEEK:
^~~~
选择合适的gcc版本非常重要。
如果在centos系统上,可以参考这篇文章进行gcc的版本切换:在centos上通过yum直接安装最新版gcc和开发工具
scl enable devtoolset-6 bash
切换后c++,g++等就指向了g++ - 6。
如果没有root权限,或者不是centos系统,那么可以进行如下操作:
make CC=gcc-6 CPP=g++-6 CXX=g++-6 LD=g++-6
这样可以不用苦逼地去修改makefile文件,直接在make时指定gcc的版本。
可以节省大量的去手动修改makefile文件的时间。
参考:c++ - Set GCC version for make in shell - Stack Overflow
另外一个做法如下:
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
还一个做法是更改系统的c++链接:
-> # update-alternatives --config c++
There are 2 choices for the alternative c++ (providing /usr/bin/c++).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/g++ 20 auto mode
1 /usr/bin/clang++ 10 manual mode
2 /usr/bin/g++ 20 manual mode
Press <enter> to keep the current choice[*], or type selection number:
————————————————
版权声明:本文为CSDN博主「zhang0peter」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhangpeterx/article/details/97256638