1

I am trying to build something that requires CMake, however when I try:

cmake -DBUILD_EXAMPLES=YES -DBUILD_TESTS=YES

I get the error:

Your systems default compiler is GCC.  This project makes use of c++11
features present only in versions of gcc >= 4.9.  You can use a different
compiler by re-running cmake with the command switch "-D
CMAKE_CXX_COMPILER=<compiler>"

I have tried using CMAKE_CXX_COMPILER=c++11 and CMAKE_CXX_COMPILER=g++11 but those get errors too. Is this because I am using the wrong variable or because I don't have c++11 installed? What would be the fix for it?

4

1 回答 1

3

看起来你的编译器太旧了。一定要检查输出gcc -v

如果您不想替换系统的默认编译器,可以在命令行中指定替代编译器,如下所示:

CXX=g++49 CC=gcc49 cmake -DBUILD_EXAMPLES=YES -DBUILD_TESTS=YES <path_to_source>

whereg++49gcc49是系统上替代编译器的名称。

大多数 Linux 发行版允许同时安装多个版本的 gcc,因此您应该能够轻松实现这一点。

于 2014-06-16T08:59:34.273 回答