使用Premake配置MSVC工具链时无法切换C++版本问题
解决Premake配置MSVC工具链时C++版本不生效的问题
问题出在你用了GCC/Clang风格的编译选项--std=c++17,MSVC根本不识别这个参数,所以配置完全没起作用,VS还是默认用C++11。
Premake本身提供了跨编译器的C++标准配置属性,不用手动加编译选项,直接按下面的方法修改:
- 把原来的
buildoptions "--std=c++17"替换成cppdialect "C++17",这个属性会自动根据当前工具链生成对应参数——对MSVC生成/std:c++17,对GCC/Clang生成--std=c++17,完美适配不同编译器。
修改后的完整脚本:
workspace "myname" configurations{"Release", "Debug"} platforms {"Win64", "Win32"} project "myname" kind "ConsoleApp" language "C++" files {"src/**.pch", "src/**.h", "src/**.cpp"} -- .hpp not included cppdialect "C++17" -- 替换原buildoptions行 filter "configurations:Debug" defines { "DEBUG" } symbols "On" targetdir "bin/Debug" filter "configurations:Release" defines { "NDEBUG" } optimize "On" symbols "Off" targetdir "bin/Release" filter "platforms:Win64" system "windows" architecture "x86_64" --x64 filter "platforms:Win32" system "windows" architecture "x86"
如果需要启用MSVC的严格模式(禁用非标准扩展),可以在project块里额外加一行buildoptions "/permissive-"。
内容的提问来源于stack exchange,提问作者user8322140
相关产品推荐
相关产品推荐

