Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line warning D9002: ignoring unknown option '-std=c++11'

In my CMakeList.txt file, I have the following in order to add c++11 supports:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

This works fine under Mac with Xcode. However, I get the following warning message from Visual Studio. Any idea?

Command line warning D9002: ignoring unknown option '-std=c++0x'

Other than the compile warning, the program gets compile and run with no problem. I am using VS2013. If I remove that single "set flag" line, the warning goes away.

like image 797
Yuchen Avatar asked Apr 06 '15 15:04

Yuchen


3 Answers

The -std=c++11 option is for GCC/CLang only, it is not available in Visual Studio. C++ 11 support in Visual Studio should be turned on by default. So, you should use this option for GCC-like compilers only:

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

If you are using the latest versions of CMake you might try to use new compiler features mechanism : http://www.cmake.org/cmake/help/v3.1/manual/cmake-compile-features.7.html

like image 120
jet47 Avatar answered Oct 27 '22 08:10

jet47


Use target_compile_features to get CMake to add the correct compiler flag, for C++ 11, for whichever compiler you are using

target_compile_features(mylibrary PRIVATE cxx_std_11)

or

set(CMAKE_CXX_STANDARD 11)
like image 20
DaveCleland Avatar answered Oct 27 '22 10:10

DaveCleland


Microsoft Visual Studio Compiler (MSVC) has it own set of compiler flags. In short: The solution to fix the issue is to use following command instead the one you have used.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
like image 34
Karol Król Avatar answered Oct 27 '22 08:10

Karol Król