Download

What's needed for using C++17

Hi there. I’m attempting to try out (on Windows) the new C++17 support that’s described in the 4.22 release notes, and I’m having a bit of difficulty.

First of all I tried adding CppStandard = CppStandardVersion.Cpp17; to my test project (named “QuickStart”) QuickStartEditor.Target.cs file and hitting compile in the editor.

That gives an error:

Adding that *BuildEnvironment *option to QuickStartEditor.Target.cs gives errors about missing header files, so I assume that’s not the right approach:

I tried building the editor from source with *CppStandard *set to Cpp17 and that gave some errors in the third-party code that suggested to me that the editor isn’t meant to be built in C++17 mode yet. I successfully built the editor without setting CppStandard, but then when I compiled my project using that editor it took a long time (I presume it was building the whole engine source again) and then failed with linking errors. (Sorry I didn’t make a note of the error messages for these steps, and annoyingly I can’t remember which settings I had in the .Target.cs file.)

So I’m not sure what the correct way of using C++17 is. Has anyone got it to work yet?

I’ve got this issue too, would love some kind of input, comments, thoughts or prayers.

As usual spent 2h for discovery of something which just may as well be written to begin with. So UE 4.22 + VS2019:

Edit the $project\Source$project$project.Build.cs file



PCHUsage = PCHUsageMode.NoSharedPCHs;
PrivatePCHHeaderFile = "$pch.h";
CppStandard = CppStandardVersion.Cpp17;


Where $project and $pch should be substituted with something to match your application. Technically, the custom PCH is not needed but since UE 4.21 the UE build tool wants it. Of course, this file must be created if it does not exist and can be filled in with whatever headers make sense.

Another annoyance is IntelliSense which wont get that the project is based on C++17 so I digged out the idea that you can go to Project Properties -> NMake -> Additional Options and add /std:c++17

This whole thing allowed me to use c++17 language features and part of the STL, I havent tried yet any runtime dependecies like using new (incl. vector, thread) and stuff.

Good luck with the rest!

If you modify the UnrealBuildTool, you can also use the PCH. I ran into the same issue with c++20 now (September 2020), and this is obviously a horrible hackish way to do it, but since I spent 3 hours R&Ding it, I might as well post it here:

  • Open the VS project UE_4.25\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj
  • Depending on which .NET SDK is intalled on your machine, you might need to change the target framework
  • Find the file Platform\Windows\VCToolChain.cs in that solution
  • Go to the end of the method AppendCLArguments_Global (it’s around line 537 at the time of writing)
  • Add

Arguments.Add("/std:c++latest");

there, or whatever c++ standard you want the compiler to use

  • build the solution. It should build to UE_4.25\Engine\Binaries\DotNET\UnrealBuildTool.exe

Now build your game project with the build settings set to:


PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
CppStandard = CppStandardVersion.Latest;

Thanks a lot. I just build the project and encountered lots warning and error in UE headers. But after applying these I still get some erros.