How Do I add an Include Path to my Project?

Simply put, “How Do I add an Include Path to my Project?”

I would like to add "D:\Boost\Boost_1_81_0" … and I’ve tried this using the visual studio properties (both C++ paths and nmake paths); I’ve also tried creating an empty plugin and adding to "PublicIncludePaths.Addrange( new string[] { "D:/Boost/boost_1_81_0" } ) in BoostBuild.sh (The empty plugin is called Boost).

I briefly tried sucking Boost into the plugin — but this is a waste. There is no need to “build” the code — there is some buildable code in boost, but I’m not using it. I’m looking to suck in some template code.

I tried #include "D:\Boost\boost_1_81_0\boost\spirit\include\qi.hpp" … but that was always going to fail — qi.hpp includes other things and so on.

This shouldn’t be rocket science. I get the plugin framework — so manage a dynamically loaded binary into the editor and whatnot, and to allow you to distribute it in the marketplace. I don’t see any boost plugin in the marketplace, either.

I could, of course, isolate my functions in another library or somesuch. Since I’m planning to use quite a few boost features to accelerate my development, I don’t expect that will be either good for the code or good for the project.

Help? How do I add an Include Path to my Project?

OK. I’m going to answer my own question. Been working on this on and off for a couple of weeks. Documentation is scarce and dense and not at all friendly.

You need to add the following to your MyModule.Build.cs file:

        PublicIncludePaths.AddRange( new string[] {"D:/Boost/boost_1_81_0"});

        bEnableUndefinedIdentifierWarnings = false;

… where (say) d:\Boost\boost_1_81_0 is where you unpacked Boost.

The 2nd line — about the warnings is required to make it shut up about substituting a 0 for #ifdef’s … typically placed around header files that are more portable (like boost).

With these two changes #include <boost/spirit/include/qi.hpp> works.

2 Likes

OK. Replying again. This is very frustrating because the configuration of the Unreal Editor an subsequently the configuration that applies to Visual Studio are complex, obtuse and often (in the programming sense) lazy. So the question is not answered.

Here’s the status … if I added the #include <boost/spirit/include/qi.hpp> to my Actor class, it complained it couldn’t load it. So I added to a module file that wasn’t being used as an Unreal class, and that worked — or seemed to work. Now that I examine things, the #include is still underlined by the automation in VS … but the fact that things compiled fooled me into thinking that I has solved things.

It was only after I made a non trivial function using boost and then make a point in my Actor class that called it … that I finally get the “cannot load file” error.

So: How do I add an include path to my project?

(Hint: y’know … this should be a simple question)

1 Like

… bump. Really… nobody knows how?

How do I add an (external) Include Path to my C++ Unreal 5.1 project?

Trying to build a Python API to interact with the Unreal simulation using boost and currently facing the same issue as you. Would be great if someone could help out!

1 Like

You might need to make a python plugin — where your python plugin creates a static or shared library.

You still need to likely include from that plugin — but things are slightly different

… and also the same.

I’m wondering if I should just create a boost symbolic link in my project directory. Don’t have time to try it today, tho.

Managed to include the boost library by copying the contents from /usr/include/boost (on Linux that is) to Source/Private in the UE project. This allowed me to include the boost headers, however, on Linux this resulted in a whole bunch of other issues, but maybe it works for you. The issues on my end were related to some Visual Studio compiler macros not available in the Linux compiler.

you might need to modify the project’s build settings in the Unreal Editor. Here are the steps:

  1. Open your Unreal project in the Unreal Editor.

  2. Click on the “Edit” menu and select “Project Settings”.

  3. In the left-hand sidebar, expand the “C++” section and select “Build”.

  4. Scroll down to the “Include Directories” section and click the “+” button to add a new path.

  5. Enter the path to your external include directory in the text box (e.g. “D:\Boost\Boost_1_81_0”) and click “Add Directory”.

  6. Click “Apply” to save your changes.

Now Unreal build system will automatically search for header files in the specified directory when building your project. You should now be able to include headers from your external library in your project’s C++ code.

After making these changes, you should be able to include Boost headers in your C++ code using the #include :eyes:

I really didn’t think that sucking all of Boost into my private source was the sustainable way to do this.

So… when I open that in my Unreal 5.1 project, the left panel has the following major sections:

  • Project
  • Game
  • Engine
  • Editor
  • Platforms
  • Plugins

None of these have a C++ sub-heading.

Ups my bad, the steps I provided are not applicable for Unreal 5.1 as the build settings have been changed.

  1. Open your Unreal project in the Unreal Editor.

  2. In the main menu, click on “File” → “New C++ Class”. This will open the “Add New C++ Class” dialog.

  3. Choose the class type you want to create, set the class name, and click “Create Class”. This will create a new C++ class and add it to your project.

  4. In the Solution Explorer, right-click on the project name and select “Properties”.

  5. In the “Configuration Properties” section, click on “VC++ Directories”.

  6. In the “Include Directories” section, click on the down arrow and select “Edit…”. This will open the “Include Directories” dialog.

  7. Click on the “New Line” button and add the path to your external include directory (e.g. “D:\Boost\Boost_1_81_0”).

This my do the thing :eyes:

Hmm. trying to get this to work in 5.2

Basically want a shared library that can be linked to all of my UE projects so I’m not duplicating assets.

This may or may not be useful Wrapping a third party library using an Unreal Engine Plugin | unrealcode.net