How to build a C++ project in Ubuntu Linux (and C++ custom plugins)

I’ve got a project in Windows that uses C++ now I need to build it in Linux. How do I do that?

3 Likes

Linux is not my strength so perhaps some of this is obvious to more experienced Linux users, but I couldn’t seem to find the answers laid out in a nice easy do this then that so hopefully everyone else can benefit from my last few days of bashing my head against a wall.

So first, you need to do a custom build of UE4 for Ubuntu. I know this sounds scary, but Epic really did a good job laying this one out. Just follow their step-by-step instructions in the documentation:

It is big, and it will take a while. I just let it build overnight.

Now if you’re just doing Blueprints, then you’re good to go, but that’s not why you’re reading this are you? I pulled my project off of SVN (RabbitVCS is a good Ubuntu equivalent to Tortoise SVN on Windows) so I’m starting with a clean copy of my code and no intermediate files leftover from other platforms (Build, Config, Content, Plugins, Source, and your .uproject file).

Plugins

If you don’t use any custom plugins OR any marketplace plugins, you can skip to the Main Project section.

I’ve had a complicated relationship with plugins. In UE4.26 I put all my custom AND marketplace plugins in a separate project (basically an empty project) in the Plugins subfolder. You’re going to need to recompile all of them to match your custom build of UE4. To help with this, I use a bash script (the Linux equivalent of .bat files in Windows) by creating a new file next to my plugin .uproject file that I creatively called BuildLinuxPluginsScript. You can use gedit for a notepad equivalent text editor to modify it:

#!/bin/bash

bash /home/user/Documents/UnrealEngine-4.26/Engine/Build/BatchFiles/RunUAT.sh BuildPlugin -Plugin="/home/user/Documents/Unreal Projects/MyPlugins426/Plugins/KantanCharts/KantanCharts.uplugin" -Package="/home/user/Documents/Unreal Projects/MyPlugins426/Package/KantanCharts" -CreateSubFolder -TargetPlatforms=Linux

(Duplicate the last line and update each one for every custom and marketplace plugin you have). Save your file, then at a terminal, use the command chmod +x BuildLinuxPluginsScript. You can now execute your script from the terminal using ./BuildLinuxPluginsScript and if all goes well, you should have a Package subdirector of your project with each plugin in its respective subfolder. Within each plugin subfolder should be at least a Binaries, Intermediate, Resources, and Source folders, and a .uplugin file. If there isn’t, you may need to go back to your plugin source file, edit the .uplugin file with a text editor and in the “Modules” section add a WhitelistPlatforms so it looks like this:

"Modules": [
		{
			"Name": "MyCustomPlugin",
			"Type": "Runtime",
			"LoadingPhase": "Default",
			"WhitelistPlatforms": [
				"Linux"
			]
		}
	]

If Linux is already in the list, try removing other platforms listed there. Sometimes the tools can be grumpy about that. Run your BuildLinuxPluginsScript again.

Once all your plugins are built, copy the packaged folders into your custom engine build. In my case they all go in /home/user/Documents/UnrealEngine-4.26/Engine/Plugins

Main project

Now your engine is loaded up with any of the plugins you need, now onto the main project. If you’re your plugins were C++ or you had marketplace plugins, but the rest is blueprint then you’re probably good to go. However, if your main project is also C++ then you’ll probably get an error about modules (your main project) being out of date and would you like to rebuild. On windows, you just say yes and it works. On Linux, not so much. Again I make a new bash file which I called LinuxGenerateProjectFiles with the following contents:

#!/bin/bash

bash /home/user/Documents/UnrealEngine-4.26/Engine/Build/BatchFiles/Linux/RunMono.sh /home/user/Documents/UnrealEngine-4.26/Engine/Binaries/DotNET/UnrealBuildTool.exe -makefile -project="/home/user/Documents/Unreal Projects/MyProject/MyProject.uproject" -game

And again chmod +x LinuxGenerateProjectFiles. Now it’s important that your project is cleaned up before you run this. If you have any plugins that you already built and installed to the engine with the previous step, remove them otherwise they’ll be “discovered” as part of this process and added to the make process. As a precaution, I also remove an intermediate and binaries folders. Now you can run this script with ./LinuxGenerateProjectFiles . After a few minutes you should have a whole bunch of new files in your project directory, but the important one here is the make file. One last command from the terminal: make MyProjectEditor (where you replace “MyProject” with your project name eg “YourProjectEditor”). The make file has a whole lot of different things it can do, but this one seems to be the key to opening your project. After that process finishes, you should be able to just double click on your project and it will start loading!

One last note, if you’ve never loaded a UE4 project on your machine before, or even the first time loading a new project, depending on the size of your project it can take quite a while. I’m working with a fairly large project and the first time it took almost 30 minutes to open so be patient! After the first time, it usually only takes my project a minute or so to load. Good luck!

3 Likes

Thank you, so much.