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.
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
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)
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")
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