问题
I am compiling a project that uses CMake which assumes the compiler is G++, but I am actually using Visual Studio 2013. In the CMakeLists.txt
file, I encountered the line
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic")
I think I ought to replace with something like
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ????") # what goes here??
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic")
endif()
I am fairly new to the world of Visual Studio, so although I know what the G++ flags mean, I don't know their Visual Studio equivalents. I think:
-std=c++11
tells G++ to use C++ 2011, which I think is the default in Visual Studio 2013, so I don't think I need a flag for that.-Wall
seems like it probably corresponds roughly to/W4
, and-Wextra
corresponds roughly to/Wall
? But on VS,/Wall
encompasses/W4
, so/Wall
is enough on its own?-pedantic
checks for strict conformance to C++ standard. No idea what the VS equivalent might be.
Can anyone confirm the right flags to use is Visual Studio?
回答1:
I'm using Visual Studio 2015 but i don't expect any major differences in these flags:
- C++11 is standard, but you should check the Support for C++11/14/17-page just to be sure and maybe upgrade to VS2015-compiler.
- Visual Studio has a "Warning-Level" where you can choose between /W0-/W4 and /Wall. So using Visual Studio itself you cant specify both /W4 and /Wall which leads me to the conclusion that /Wall is sufficient.
- The closest i could find to "pedantic" is something i would translate (sry, german VS here) to "deactivate language-extensions" and is the option /Za
来源:https://stackoverflow.com/questions/35398878/visual-studio-equivalent-for-these-g-flags