Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake keeps adding the std=gnu++11 option

Tags:

std

macos

gcc

cmake

I'm trying to compile a project in C++ using cmake, and in the page of the project they tell me that it will crash if I don't add the standard 98. (I'm on a mac) I've tried all I found on the internet and I could manage to make the cmake use the option -std=c++98 but it also adds -DNDEBUG -std=gnu++11. (I saw it using the make VERBOSE=1 option)

I would like to get rid of that. Using the --trace option I could see that the option is set in a file which is in the cellar folder, that is, is something that has to do with cmake itself and not in the CMakeList.txt file im using.

How can I solve this problem?

If it can help the code I'm trying to compile is this: SAMoS

Thank you.

UPDATE:

with the --trace option I was able to see that the -std=gnu++11 option was selected in the file:

/usr/local/Cellar/cmake/3.9.4.1/share/cmake/Modules/Compiler/GNU-CXX.cmake which can be seen here GNU-CXX.cmake

If I eddit that file in a way that every if sets the option to -std=c++98 then, the cmake complains giving me the next error:

CMake Error in src/CMakeLists.txt:

The compiler feature "cxx_nullptr" is not known to CXX compiler

"GNU"

version 7.2.0.

I don't know what else can I try...

like image 703
Manuel Pena Avatar asked Nov 06 '17 00:11

Manuel Pena


People also ask

Does CMake come with GCC?

CMake generates files for other build systems. These can be Makefiles, Ninja files or projects files for IDEs like Visual Studio or Eclipse. The build files contain calls to compilers like GCC, Clang, or cl.exe.

Does CMake need compiler?

It is used in conjunction with native build environments such as Make, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system. CMake is distributed as open-source software under a permissive BSD-3-Clause license.

How does CMake select compiler?

When CMake executes the project() call, it looks for a default compiler executable and determines the way for use it: default compiler flags, default linker flags, compile features, etc. And CMake stores path to that default compiler executable in the CMAKE_C_COMPILER variable.

What does CMake do in Linux?

CMake is an open-source, cross-platform tool that uses compiler and platform independent configuration files to generate native build tool files specific to your compiler and platform. The CMake Tools extension integrates Visual Studio Code and CMake to make it easy to configure, build, and debug your C++ project.


1 Answers

You need to set the language standard:

set(CMAKE_CXX_STANDARD 98)

Depending on the compiler, it may enable extensions as well. To disable the GNU extensions also add:

set(CMAKE_CXX_EXTENSIONS OFF)

Note that setting this options does so only for the specified target and dependent targets.

Have take a look at this section of the CMake manual for more information on compiler features. Do note however, using this

like image 142
Cinder Biscuits Avatar answered Oct 23 '22 18:10

Cinder Biscuits