Mixing C and C ++ sources in cmake
I am trying to compile C and C ++ source codes. I am currently using the C ++ 0x standard for C ++ by adding this line to my cmake file add_definitions(-std=c++0x)
.
At compile time, I get the following warning: cc1: warning: command line option β-std=c++11β is valid for C++/ObjC++ but not for C [enabled by default]
and this error: error: βforβ loop initial declarations are only allowed in C99 mode
refers to the for loop in the c code.
I am wondering how I can set a standard for c code in a cmake file.
source to share
You shouldn't use add_definitions
for this, instead do something like
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
-std=c99
if you want to get the initial loop declarations.
add_definitions
for definitions such as -DUSE_SOME_LIBRARY
.
source to share