Plugin using external library that contains cpp files without include statements

I have successfully created and compiled a blank plugin using the method described in the following tutorial:

which includes the following steps:
  • create new blank c++ Unreal project
  • Add Plugins directory to the project directory
  • create a PluginNAME folder within the plugins directory
  • create the required files and folders within the PluginNAME directory
  • build the plugin

The next thing I want to achieve is to include the source files from a different external c++ library in the plugin, so that I can link the external library with the Unreal engine.

The first problem I have run into is that Unreal expects all modules to have include statements, as stated in the following error:

Severity	Code	Description	Project	File	Line	Suppression State
Error		Source file [PATH to external library cpp] is not including any headers.  We expect all modules to include a header file for precompiled header generation.  Please add an #include statement.

The external library I’m using is broken into individual modules. These modules are structured such that there are numerous .cpp files without include statements, and all of the .h files are included in global module include files. Seemingly, this structure wont work with Unreal’s expectation that all cpp files have include statements.

My Plugin directory looks like this:

  • PluignNAME
    • PluginNAME.uplugin
    • Resources
    • Source
      • PluginNAME
        • PluginNAME.Build.cs
        • Private
          • PluginNAME.h
          • PluginNAMEPCH.h
          • Module.cpp
          • Module.h
          • ExternalLibrarySource
            - list of external library files

I only need to add the files to the VS project in order to get the error. It appears even if none of the external library files are #included or referenced anywhere in the plugin code.

My question: Is there any possible work-around in order to combine the include structure of the external library with the expected include structure of Unreal?
Am I mistaken when I assume that the error indicates that Unreal expects all .cpp files to have include statements? (I notice it mentions that “we expect all MODULES to include a header file …”) this indicates that there might be some way of structuring my plugin so that I don’t get this error …

Hi HangarSeason,

One of the ways to include external libraries is to mention them in your plugin’s build.cs file. Unreal uses a custom build tool called unreal build tool (UBT) that is written in c#. Using these build.cs files you are telling the UBT what the dependencies are and where they are located. Mybe you can put your external libraries under the ‘Resources’ folder in your plugin and mention the path in your build.cs file. You can add the paths to your libraries using the PulicIncludePaths.AddRange and PrivateIncludePaths.AddRange objects as shown below.

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

			PrivateIncludePaths.AddRange(
				new string[] {
					// ... add other private include paths required here ...
					
				}
				);

Hope this helps.

Thanks

Exactly the simple solution I was looking for, thanks a lot!