Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake disable -std=c++11 flag for C files

I'm trying to build bkchaind. One build option is to use cmake, so I installed it with Homebrew (OSX 10.9.1). When I do cmake, though, I get:

[  2%] Building C object json-rpc-cpp/src/jsonrpc/CMakeFiles/jsonrpcStatic.dir/connectors/mongoose.c.o
error: invalid argument '-std=c++11' not allowed with 'C/ObjC'

I am none too sure why cmake would try to pass a C++-specific compiler option to a C/ObjC file. If I comment out this line in the main CMakeLists.txt file:

ADD_DEFINITIONS(-std=c++11)

then it no longer passes the flag to any file. However, the C++ files do need it. How do I get cmake to include the flag for C++ files, but not for C files?

like image 301
Claudiu Avatar asked May 22 '14 23:05

Claudiu


1 Answers

Use CMAKE_CXX_FLAGS to set c++ specific flags:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
like image 131
Anycorn Avatar answered Oct 29 '22 11:10

Anycorn