I am trying to compile a C and C++ source codes.
Currently I am using c++0x standard for C++ by adding this line to the cmake file add_definitions(-std=c++0x)
.
During the compilation, 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
referred to a for loop in the c code.
I am wondering how can I set a standard for c code in the cmake file.
You should not use add_definitions
for that, 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 loop initial declarations.
add_definitions
is for definitions like -DUSE_SOME_LIBRARY
.
Instead of add_definitions
you should use something like this instead:
set(CMAKE_CXX_FLAGS "-std=c++0x")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With