[Project] Failed to Generate Code

Hello!

I have an issue with code spontaneously no longer building. My changes have been relatively minor, but I’m getting a completely unhelpful error message that just says ‘Failed to Generate Code’. I’m unsure how to progress.

Thanks!

Edit: It looks like none of the generated headers are being generated by the UHT. There’s nothing in the output logs indicating any failure except ‘Failed to generate code’ and ‘UnrealHeaderTool failed for target’. These error messages are painfully vague.

So, to put an answer down for the record:

Preprocessor directives such as an #if directive are presently to be avoided.
Circular dependencies can cause the UHT to fail and generate the above error.

Thanks everyone.

You can’t use the “Compile” button inside Rocket if you change any of the headers. You can change the code in the .cpp files and that’s fine - but it apparently skips the pre-processed header build step. Maybe that’s your issue?

Hi Neil,

I’m not compiling from within the editor, this is happening inside of Visual Studio.

Can you copy and paste the entire output from Visual Studio then? That’s not a message you’d typically see.

I could, but I have an idea of what the issue is and am able to get building again. It would seem I had a circular dependency that wasn’t immediately obvious, and that the UHT has trouble with said circular dependency - it would be nice for it to throw a specific error when this is the case to make it easier to find; I resorted to commenting out the majority of my code base and putting it back in piece by piece.

I was additionally using an #if directive, and I’m not sure that the UHT can handle that either. I’m assuming it does not do any form of pre-processing at present?

Hi Luke,

That is correct. There is limited preprocessing in that UHT understands the CPP macro and NULL, and follows #include dependencies, but that’s about it really. It certainly won’t like your #if.

Steve

Thanks Steve!

Are there any plans for the UHT to be able to deal with more involved preprocessing in future? Things like #if directives would be quite handy.

It’s certainly a much-requested feature and thus is on our list of things to look at, but it is non-trivial due to the current build model. At the moment, UHT treats each header individually and has no notion of what the compiler ends up seeing.

So, for example, you may have a macro 3 levels deep in a PCH file, which is included by every .cpp, which it includes before your header. The compiler then ‘sees’ the define when it parses your header. UHT isn’t involved in any of that process. If it had to repeat a full PCH pass beforehand, it would seriously cripple builds speeds and programmer workflow.

In short, it’s not something we can just ‘turn on’… there’s a lot to be considered and other things need to happen before it can be attempted. But it is something we want to do.

Steve

Thanks Steve, that’s all I needed to know :slight_smile:

Hi guys,

just tried to build UE4 and I get the same or at least similar error:

1 error : Failed to generate code for UE4Editor D:\Programme\GitHub\UnrealEngine\Engine\Intermediate\ProjectFiles\EXEC UE4

2 error : UnrealHeaderTool failed for target ‘UE4Editor’ (platform: Win64, module info: D:\Programme\GitHub\UnrealEngine\Engine\Intermediate\Build\Win64\UE4Editor\Development\UnrealHeaderTool.manifest). D:\Programme\GitHub\UnrealEngine\Engine\Intermediate\ProjectFiles\EXEC UE4

3 error MSB3073: Der Befehl “…..\Build\BatchFiles\Build.bat UE4Editor Win64 Development” wurde mit dem Code -1 beendet. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 UE4

But I didn`t change anything, just followed the ‘Downloading and Building UE4 Source’ video.

what could cause it? any idea?

already solved it myself. I just missed reading the comment about to make sure to have installed the June 2010 DirectX runtime. Once done, everything compiled perfectly.