[英]How to enable C++17 mode with UnrealEngine 4.19 on VS 2017?
UnrealEngine 4.19 uses Visual Studio 2017's C++14 mode as default. UnrealEngine 4.19 默认使用 Visual Studio 2017 的 C++14 模式。 The Visual Studio 2017 compiler has a flag /std:c++17
to enable C++17 and subsequently things like <optional>
for std::optional
. Visual Studio 2017 编译器有一个标志/std:c++17
来启用 C++17 和随后的诸如<optional>
类的东西 for std::optional
。
I tried adding the following line to VCToolChain.cs ( C:\\Program Files\\Epic Games\\UE_4.19\\Engine\\Source\\Programs\\UnrealBuildTool\\Platform\\Windows\\VCToolChain.cs
):我尝试将以下行添加到 VCToolChain.cs ( C:\\Program Files\\Epic Games\\UE_4.19\\Engine\\Source\\Programs\\UnrealBuildTool\\Platform\\Windows\\VCToolChain.cs
):
void AppendCLArguments_Global(CppCompileEnvironment CompileEnvironment, VCEnvironment EnvVars, List<string> Arguments)
{
Arguments.Add("/std:c++17");
// ... the rest of this function.
However this doesn't seem to do anything, for example #include <optional>
still results in the build error fatal error C1189: #error: class template optional is only available with C++17.
然而,这似乎并没有做任何事情,例如#include <optional>
仍然导致构建错误fatal error C1189: #error: class template optional is only available with C++17.
. . It's immensely difficult to find out anything about this or even try to find out with that compiler flags the UnrealBuildTool (UBT) is calling cl.exe
... Other answers suggested to add -verbose
to the nmake "Build Command Line" setting (so mine looks like: "C:\\Program Files\\Epic Games\\UE_4.19\\Engine\\Build\\BatchFiles\\Build.bat" DemoApp Win64 DebugGame "$(SolutionDir)$(ProjectName).uproject" -WaitMutex -FromMsBuild -verbose
but all it does is output verbose UBT messages, not compiler command-line invocation output.很难找到有关此的任何信息,甚至尝试找出 UnrealBuildTool (UBT) 正在调用cl.exe
编译器标志......其他答案建议将-verbose
添加到 nmake“构建命令行”设置(所以我的看起来像: "C:\\Program Files\\Epic Games\\UE_4.19\\Engine\\Build\\BatchFiles\\Build.bat" DemoApp Win64 DebugGame "$(SolutionDir)$(ProjectName).uproject" -WaitMutex -FromMsBuild -verbose
但是它所做的只是输出详细的 UBT 消息,而不是编译器命令行调用输出。
Short answer : Add -CppStd=Cpp17
to your UnrealBuildTool.exe
compile command.简短回答:将-CppStd=Cpp17
添加到您的UnrealBuildTool.exe
编译命令。
Strangely, this seems to be documented nowhere, I had to dig into the .cs files of the engine to find it.奇怪的是,这似乎没有任何记录,我不得不深入研究引擎的 .cs 文件才能找到它。
More specifically, in the file "C:/Program Files (x86)/Epic Games/UE_4.26/Engine/Source/Programs/UnrealBuildTool/Configuration/TargetRules.cs", there is :更具体地说,在文件“C:/Program Files (x86)/Epic Games/UE_4.26/Engine/Source/Programs/UnrealBuildTool/Configuration/TargetRules.cs”中,有:
/// <summary>
/// Which C++ stanard to use for compiling this target
/// </summary>
[RequiresUniqueBuildEnvironment]
[CommandLine("-CppStd")]
[XmlConfigFile(Category = "BuildConfiguration")]
public CppStandardVersion CppStandard = CppStandardVersion.Default;
Then, in another file, the definition of CppStandardVersion
is :然后,在另一个文件中, CppStandardVersion
的定义是:
public enum CppStandardVersion
{
/// <summary>
/// Use the default standard version
/// </summary>
Default,
/// <summary>
/// Supports C++14
/// </summary>
Cpp14,
/// <summary>
/// Supports C++17
/// </summary>
Cpp17,
/// <summary>
/// Latest standard supported by the compiler
/// </summary>
Latest,
}
So, I have generated my project files with -cmakefile
, then I have opened my CMakeLists.txt
and added -CppStd=Latest
to my Build.bat
compile command, and the error with std::optional
is gone !所以,我用-cmakefile
生成了我的项目文件,然后我打开了我的CMakeLists.txt
并将-CppStd=Latest
添加到我的Build.bat
编译命令中,并且std::optional
的错误消失了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.