Download

C++17 was disabled in PCH file but is currently enabled

Hi,
I am having difficulties enabling c++17 for my project. I am on Linux and have the engine (4.24.3-release) compiled from source.

I can reproduce this problem very simply with the following steps:

  1. create a new blank c++ project without starter content (named “MyProject”)
  2. insert

CppStandard = CppStandardVersion.Cpp17;

in Source/MyProject/MyProject.Build.cs as the first line in the constructor
3. run “make MyProjectEditor” which leads to a compile error “error: C++17 was disabled in PCH file but is currently enabled

To solve this problem, I have tried the following approaches:


rm -rf Binaries Intermediate && make MyProjectEditor

but this lead to the same error
  1. from What's needed for using C++17 - Unreal Engine Forums
    replace the constructor in Source/MyProject/MyProject.Build.cs with
and create an empty file "Source/MyProject/PCH_MyProject.h"
then run 

rm -rf Binaries Intermediate && make MyProjectEditor

but this lead to the same error
  1. from Issues with 4.22 C++17 Support - Unreal Engine Forums
    do the same as in 2. but additionally insert in Source/MyProjectEditor.Target.cs the line
    BuildEnvironment = TargetBuildEnvironment.Unique;
then run 

rm -rf Binaries Intermediate && make MyProjectEditor

which causes 1450 files being recompiled
but leads to the same error in the end

  1. from http://www.programmersought.com/article/6755566414/ where there is a proposed solution for the error “exception handling was disabled in PCH file but is currently enabled” which seems very similar to mine
in Engine\Source\Programs\UnrealBuildTool\Platform\Linux\LinuxToolChain.cs remove the line

PCHArguments += string.Format(" -include \"{0}\"", InlineArchName(BasePCHName, Arch, GPUArchitecture))

then run 

rm -rf Binaries Intermediate && make MyProjectEditor

but this lead to the same error

At this point I have no idea what I am doing wrong and what else I could try. Thank you for your help.

I went ahead and tried an earlier version of Unreal Engine out of curiosity.

In version 4.23.1-release, if I add



CppStandard = CppStandardVersion.Cpp17;


to MyProject.Build.cs it compiles fine. This is different from the behavior in 4.24.3-release where compilation already failed (previous post). However, if I then start using C++17 features such as structured bindings


#include <utility>

int foo() {
    std::pair<int, int> pr;
    auto [a, b] = pr;
    return a;
}

I get a compilation error:
"error: decomposition declarations are a C++17 extension -Werror,-Wc++17-extensions]"

It looks like using C++17 on Linux on Unreal Engine version 4.23 is not yet implemented and version 4.24 it is, but it does not quite work yet.
On Windows it seems supported already from version 4.22, as discussed here and here.

Can anyone confirm that C++17 indeed not yet supposed to work in Unreal Engine on Linux yet? Otherwise I still believe I might be missing something.

I am very interested in getting UEBT to behave with C++17 on linux as well. No matter what I try (non-unity build, disable PCHs altogether, make PCHs private, make the build environment unique), the build tool always wants to recompile the entire editor (which is annoying as hell and does not happen on windows) and then either stops when it sees non c++17 compliant code in the engine, or compiles the engine successfully (with the 14th standard presumably) and then complains about the “C++17 disabled in PCH” thing.

Right now I think the only way to make it all work is as follows: disable PCH files yet prohibit the engine from trying to recompile itself from scratch. No combination of build flags that I’ve tried so far managed to achieve this.

Can we somehow summon someone from the UE team to help us with this undocumented mess?

Man, I moved to linux, but sadly this error: C++17 was disabled in PCH file but is currently enabled, stopped me like a wall. I already tried EVERYTHING, if someone have a fix please let us know :frowning:

Have you found any info on this?

C++17 setting is not supported on linux yet, since the script in UBT was hard coded to pass C++14. It should work in 4.25.

I can confirm it now works in 4.25

I configured Source/MyProject/MyProject.Build.cs with


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

and it compiles successfully with c++17.
Thank you for making this work, it is very appreciated.

Unless you can enable it for the Editor target as well, how do you even test cpp17 specific code?

Hi guys,

Im having a similar issue but only when trying to compile to Android.

" 1 error generated.
LogPlayLevel: [17/42] X.cpp [armv7]
LogPlayLevel: Error: error: C++17 was disabled in PCH file but is currently enabled"

It does happen with a bunch of files. Not sure how to proceed

Any hints?

Thanks,
Juan