Robotics StackExchange | Archived questions

How to enter compiler flags into CMakeLists

When I compile my ROS code, I'm getting a ton of warnings like:

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11

According to this SO question I need to add -std=c++0x to my compiler's flags.

I see in my auto-generated CMakeLists.txt, there's already the commented-out option:

 #set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")

so I changed that to:

 set(CMAKE_C_FLAGS "-std=c++0x ${CMAKE_C_FLAGS}")

However, when I re-run catkin_make --pkg mypackage I still see these warnings. I tried the other flags suggested in the SO question, but the output is the same. Why is CMake ignoring CMAKECFLAGS?

Asked by Cerin on 2016-07-20 10:32:56 UTC

Comments

Answers

CMAKE_C_FLAGS are for compiling C files, but you're building C++ files, so you need to set the CMAKE_CXX_FLAGS variable.

The CMake documentation includes a list of useful variables and describes what they're used for.

Asked by ahendrix on 2016-07-20 11:11:11 UTC

Comments