I’m getting the following build error when I’m trying to package my game:
Error C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc
These errors originate from the Boost library that I’m trying to build with my project, and the errors happen everywhere that they use their “BOOST_SYSTEM_NOEXCEPT” macro. These errors only occur when packaging, if I build in Development_Editor I don’t see these errors.
Is there a way I can fix these errors? How can I specify the /EHsc flag?
NOTE: Answers below will depend heavily on engine version, try many of them before you give up!
For Unreal 4.18 in the [ProjectName].Build.cs file, the constructor parameter is now ReadOnlyTarget rules and I got an error using: bForceEnableExceptions = true;
I made it work by editing [ProjectName].Target.cs in the directory above. Adding bForceEnableExceptions = true; there fixed my build so I could use exceptions.
In 4.19.2 none of the above answers will fix this issue if you build in shipping mode on Visual Studios 17.
In order to fix this, you must add a line to Engine/Source/Programs/UnrealBuildTool/Platform/Windows/VCToolChain.cs inside the function AppendCLArguments_Global:
Arguments.Add("/EHsc");
This line will handle the compiler exception and you should be good to go!
In 4.19.2, the probably best way to do this is in the MyProject.Build.cs file, just by adding bEnableExceptions = true;.
But yea it is completely non-obvious and it took me hours to find a solution that works… But I think this is the one to go, as no global toolchain files have to be modified.
using UnrealBuildTool;
public class MyProject : ModuleRules
{
public MyProject(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
bEnableExceptions = true; // Add this...
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
}
}
Funny you should mention that. I tried that. It doesn’t work in 4.19.2 when you have visual studios 2017. Hence the adding of the compiler argument into the toolchain.