Syntax errors in InputCoreTypes.h when my plugin imports the file

Edit: Oops, title should be include, rather than import. Had python on the brain :slight_smile:

Hey guys, I am developing a plugin on a 4.6 release fork using Visual Studio community edition, windows 7 x64. The central module for the plugin is using IInputDeviceModule, so clearly I am going to need access to the Input core types, such as FKeys, FKeyDetails, Ekeys.

However, when a private cpp file in my plugin includes InputCoreTypes.h, I get these syntax errors when trying to build the UE4 project when it gets to my plugin:


1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(66): error C2143: syntax error : missing ';' before '<'
1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(66): error C2913: explicit specialization; 'TStructOpsTypeTraits' is not a specialization of a class template
1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(66): error C2059: syntax error : '<'
1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(66): error C2059: syntax error : 'public'
1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(67): error C2143: syntax error : missing ';' before '{'
1>C:\projects\UnrealEngine\Engine\Source\Runtime\InputCore\Classes\InputCoreTypes.h(67): error C2447: '{' : missing function header (old-style formal list?)

This is what InputCoreTypes looks like around there:


template<>
struct TStructOpsTypeTraits<FKey> : public TStructOpsTypeTraitsBase
{
	enum
	{
		WithSerializeFromMismatchedTag = true,
		WithExportTextItem = true,
		WithImportTextItem = true,
		WithPostSerialize = true,
	};
};

So I think it has something to do with the fact that this struct is not exposed in the InputCoreAPI? Just guessing.

This is what my Build.cs looks like for the plugin:


namespace UnrealBuildTool.Rules
{
	public class MIDIControl : ModuleRules
	{
		public MIDIControl(TargetInfo Target)
		{
			PublicIncludePaths.AddRange(
				new string] {
					// ... add public include paths required here ...
				}
				);

			PrivateIncludePaths.AddRange(
				new string] {
					"Runtime/MIDIControl/Private",
					// ... add other private include paths required here ...
				}
				);

			PublicDependencyModuleNames.AddRange(
				new string]
				{
					"Core",
					// ... add other public dependencies that you statically link with here ...
				}
				);

			PrivateDependencyModuleNames.AddRange(
				new string]
				{
					
					"InputCore",
					"InputDevice",
					// ... add private dependencies that you statically link with here ...
				}
				);

			DynamicallyLoadedModuleNames.AddRange(
				new string]
				{
					// ... add any modules that your module loads dynamically here ...
				}
				);
		}
	}
}

The code that is including InputCoreTypes.h is in the private source for my plugin. Any ideas on what I am doing wrong? Thanks

At this point, I believe you solved it. But there’s a syntax error in the enum inside the struct. After “WithPostSerialize = true” there shouldn’t be a comma, since it’s the last enum member.

Trailing commas in C++ enumerations are legal, though not required.

Many programmers feel that it is good practice to reduce the number of lines that change in a diff and to avoid the annoyance of forgetting to put it in when you add a new value.

An alternate approach is to always put the commas at the start of lines, so you don’t have the diff problem or the somewhat odd trailing comma. This style is very common with constructors so that your spacing ends up the same with the colon on the first line and then commas on the rest of them (also trailing commas aren’t legal in that case).

I’m curious as to what the solution was. I’m getting the identical errors when packaging a plugin that extends uboxcomponent which ultimately includes InputCoreTypes.h.

Also curious about the fix - why does using InputCore in a plugin cause these errors? What’s the usual solution?

The error was introduced when my module’s PCH .cpp file included InputCore.h. Replacing this include with Engine.h (which eventually includes InputCore) fixed it. Directly including InputCore.h was the problem. Hope this helps! This is what my module’s private dependencies looks like… I include Slate so that I can send input events the the slate application.

Hmm, unfortunately I’m not including InputCore.h directly. Seems to be tied to including GlobalShader.h for me.

Why is it that you have those modules under private dependency rather than public?

EDIT: Included “Engine.h” before the “GlobalShader.h” include, and it seems to compile fine. So weird!

No reason in particular, its just the only code that needs those modules is cpp files in my module’s private directory. They could be public if you wanted though.