Linking 3rd party SDK library / developing plugin. Need help with the setup

Hi, I hope this is the right section for this topic. :slight_smile: I’ve tried asking my questions on the answer hub earlier but I’m not getting any responses there. It probably requires quite an in-depth explanation so maybe a forum thread is better suited. Mind that I have some C++ experience, but that’s mostly with the syntax. I’m still trying to wrap my head around how C++ does stuff, how linking works and what sorts of frameworks people build with it.

Let me explain my problem. I’m doing a university assignment in which I’m trying to get the Vicon motion capture system to work with UE4. This is done by using the Vicon DataStream, basically a way for the motion capture system to stream its live captured data over the network to another machine. To build applications that receive this data, the Vicon SDK provides the following files:

  • ViconDataStreamSDK_CPP.dll
  • ViconDataStreamSDK_CPP.lib
  • Client.h

I have two variants of all these files, one for Win32 and one for Win64. More info in the SDK manual.

Initially I tried following the UE4 plugin development tutorial, but there weren’t any good example of how this is created when using 3rd party libs. I constantly get “game code could not be compiled” error when I fire up the editor, without any feedback on where I’m going wrong. Next I tried looking at the Linking Static Libraries Using The Build System tutorial, but I think I’m missing a few steps to actually get it to load. First I just want UE4 to load the SDK library, after that I have to figure out how to expose its functionality to Blueprints.

I’m probably doing a few things wrong (I tried a lot of things, and I don’t think it’ll be of much help if I laid out everything here or my post would end up being 3x as long), so I was hoping I could contact someone more knowledgeable with the UE4 build system to help me out. I’d hugely appreciate it! I’ve been cracking my head on this for weeks now, and I’ve grown increasingly frustrated with my lack of understanding. How do I go about creating a UE4 plugin for this SDK?

The naming in that Linking Static Libraries tutorial is a bit confusing, too much magic. Anyway, what you want to do first is wrap the Vicon library in a UBT module (an external one), after you’ve done that you can add the module as a dependency to your project/plugin just like any other UE4 module. To wrap the library in a UBT module you need to create a Build.cs file for it in one of the source directories that UBT trawls, if you’re building the engine from source you can create a new directory called Vicon under Engine\Source\ThirdParty and put the Build.cs there, you can also put the Vicon SDK in there (this is optional, it just makes it simpler to work with relative paths in the Build.cs). There are plenty of examples of Build.cs files for external modules in that ThirdParty directory, Box2D, Vorbis, Ogg.

Yeah, that’s sort of what I’ve been trying to do based on the Linking Static Libraries tutorial, I think. Do I need to build the UE4 source code for this, or can I just contain it within my UE4 project? I created a Visual Studio project for my UE4 project, but I don’t know where to go from there. I’ll try to give a more detailed overview of what I tried later today.

You can put it in the source directory of your project.

Ok, so I created the following directories:

OculusRiftVicon/Source/ThirdParty/Vicon
OculusRiftVicon/Source/ThirdParty/Vicon/Includes
OculusRiftVicon/Source/ThirdParty/Vicon/Libraries

I put the ViconDataStreamSDK_CPP.x86.lib and ViconDataStreamSDK_CPP.x64.lib in the above Libraries folder. I put the Client.h in the Includes folder.

I then created the following Vicon.Build.cs, and put it in the ThirdParty/Vicon folder: using System.IO;using UnrealBuildTool; public class Vicon : ModuleRules{ - Pastebin.com

When I fire up the UE4 editor, it makes no mention of loading or compiling the code. I assume it won’t get compiled until I actually reference it in a plugin or something?

Anyway, next I create the plugin folders:

OculusRiftVicon/Plugins/ViconPlugin
OculusRiftVicon/Plugins/ViconPlugin/Source/ViconPlugin

This is the ViconPlugin.uplugin file I made and placed in the Plugins/ViconPlugin folder: { "FileVersion" : 3, "FriendlyName" : "Vicon Plugin", "Version" : 1, - Pastebin.com

And this is the ViconPlugin.Build.cs I put in the Plugins/ViconPlugin/Source/ViconPlugin folder to test: namespace UnrealBuildTool.Rules{ public class ViconPlugin : ModuleRules - Pastebin.com

Now when I start the editor, it first gives a message whether I want to recompile my project modules. I select yes. It then comes with the message that the game code could not be compiled, without any further information. This is pretty much where I’m stuck right now. Am I on the right path? What am I missing?

While there have been vast improvements in hot-reloading and in-editor compilation lately, I think those changes are only in 4.4, so… You need to build your plugin and project before you launch the editor. Right-click on the .uproject and generate Visual Studio files, then double-click the generated .sln to open it in Visual Studio, build your project, then double-click on the .uproject to open it in UnrealEd. Once there you should be able to enable your plugin from the Plugins window.

Also, instead of using a hard-coded full path to specify the ThirdPartyPath in your Vicon.Build.cs I’d suggest constructing one from this one:



// path to directory where this .Build.cs is located
Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name));


Alright (changed Vicon.Build.cs to this: using System.IO;using UnrealBuildTool; public class Vicon : ModuleRules{ - Pastebin.com). To keep it simple, I started a fresh UE4 project (based on a template with some starter content). I then added the Plugins/ViconPlugin and Source/ThirdParty/Vicon folders and files. Then I click Generate Visual Studio project Files on the .uproject file.

But now it has new problems and fails to generate the project files, with the following message:

Ok then. So I remove the Plugins and Source folders I added. Now I do manage to create a Visual Studio project file (I have VS 2013 installed btw). When I open the .sln file, the solution explorer is empty (Solution ‘OculusRiftVicon’ (0 projects)). When I re-add the Plugins and Source folder files, it does not change a thing. Trying to re-generate the VS project file results in the same error again as above.

No idea how to tackle this. What else can I try?

Which template, a C++ one or BP only? There needs to be at least one .Target.cs file in the Source directory. Code-based templates will have two I think (one for in-editor game, and one for a standalone game), BP templates don’t have a Source directory and as such do not have any .Target.cs files.

Ah ok. It’s a BP one. I thought that generating the Visual Studio project would turn it into a C++ project. Luckily I still had the OculusRiftVicon.Target.cs files from my previous OculusRiftVicon project (which was made with the same template, but I was experimenting with making C++ classes which probably made those files). I threw the following files over:

Source/OculusRiftVicon.Target.cs
Source/OculusRiftViconEditor.Target.cs
Source/OculusRiftVicon/OculusRiftVicon.Build.cs
Source/OculusRiftVicon/OculusRiftVicon.cpp
Source/OculusRiftVicon/OculusRiftVicon.h

But of course then trying to build the project is not that easy:

Slowly getting somewhere?

Hmm, double-check that the module name given to IMPLEMENT_PRIMARY_GAME_MODULE in Source/OculusRiftVicon/OculusRiftVicon.cpp matches the module name in the .uproject:



"Modules": 
        {
            "Name": "YourModuleName",
            "Type": "Runtime",
            "LoadingPhase": "Default"
        }
    ],


And if that still doesn’t get you anywhere, create a new project from the basic C++ template and copy your plugin source into there and try again.

Ok, to narrow down the issue I started anew again, this time with the Code First Person template which has a VS project set up from the get-go. Named the project ViconCPP.

When I drag the Source/ThirdParty/Vicon and Plugins/ViconPlugin in there, I still get the following build log when trying build the VS project:

However, if I remove JUST the Plugins/ViconPlugin folder:

ViconPlugin only contains ViconPlugin.Build.cs (namespace UnrealBuildTool.Rules{ public class ViconPlugin : ModuleRules - Pastebin.com) besides the .uplugin.

Btw, I only need the SDK’s .lib files right? Or are the .dlls also needed?

You need the .lib files to build, and the .dll files at runtime. You may need to specify those .dlls in Vicon.Build.cs via PublicDelayLoadDLLs.Add(“whatever.dll”). You should also add the path to the directory containing the libraries to PublicLibraryPaths, and specify only the filenames of the libraries (without paths) via PublicAdditionalLibraries.

Your project builds when you take out the plugin source because the plugin is the only thing that depends on your Vicon module, without the plugin UBT probably just doesn’t bother building the Vicon module.

… And I’ve just realized why you’re getting that unresolved external, UBT is attempting to build your Vicon module, but it doesn’t have any source. You need to let UBT know that it’s an external module that shouldn’t be built by adding the following to your Vicon.Build.cs:



public class Vicon: ModuleRules
{
    ...

    public Vicon(TargetInfo Target)
    {
        Type = ModuleType.External;
        ...



Awesome! The project now builds in VS.

However still no luck when I start up the UE4 editor. It still says the modules are missing / out of date, tries to recompile, then exclaims the game code couldn’t be compiled and that the ViconPlugin failed to load.

This is a bit weird, since I thought the editor is building the same code as in VS? What could be different?

No clue, I don’t recall it ever attempting to recompile a module that failed to load for me. At this point I’d profile the editor using Dependency Walker to see why it’s failing to load the plugin, perhaps it’s failing to locate the Vicon dlls when it tries to load the plugin.

Hm, ok. Where exactly does it expect to find the DLLs? I put them alongside the .lib files for now. I checked the UE4Editor-ViconCPP.dll with Dependency Walker but I can’t find any reference to the Vicon DLLs in it.

That seems sensible.

That won’t tell you much because there’s no hard-coded dependency between your project and the plugin, the editor will load the plugin at runtime. You need to profile UE4Editor.exe, to do so open it in DependencyWalker and press F7 to start profiling, a dialog will popup, choose the following options making adjustments to paths as needed:

UE4EditorDependencyWalker.PNG&stc=1

Then press OK and the editor will launch and open your project, enable the plugin if it isn’t already enabled then look for UE4Editor-ViconPlugin.dll under the UE4Editor-Core.dll node in the tree, then… I dunno, look for anything red. Also, there’s a button on the toolbar to switch between showing full paths and relative paths, might be helpful.

Hm, it’s not in the list under the UE4Editor-Core.dll node, went over it several times with full paths shown, so that it should be easy to spot. After that I checked if it actually existed, as it doesn’t seem VS even build the UE4Editor-ViconPlugin.dll. There’s no Binaries folder in ViconCPP/Plugins/ViconPlugin. My plugin consists of just the .Build.cs now… does it require actual code before VS builds the UE4Editor-ViconPlugin.dll? Or is this normally done when starting the editor?

(Also, thanks for your help so far. I’d never figure this out on my own in a timely manner)

Yes, a plugin needs source code, what would be the point of building something that does absolutely nothing? The editor doesn’t auto-generate plugin source.

Just making sure.

To takes things easy I copied over and adjusted the UObjectPlugin example plugin source. Meaning I now have:

ViconPlugin/Source/ViconPlugin/Public/IViconPlugin.h: #pragma once#include "ModuleManager.h"/** * The public interface to - Pastebin.com
ViconPlugin/Source/ViconPlugin/Classes/MyPluginObject.h: // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.#pragma once - Pastebin.com

I also added this to the ViconPlugin.Build.cs since it’s also in the UObjectPlugin.Build.cs:


				PrivateIncludePaths.AddRange(
					new string] {
						"ViconPlugin/Private",
					}
					);

				PublicDependencyModuleNames.AddRange(
					new string]
					{
						"Core",
						"CoreUObject",
					}
					);

Sadly nothing seems to have changed. When I build the VS project, the plugin binary isn’t created. I’m likely missing something, even though I have an almost exact copy of the example plugin.

EDIT: tried copying the whole UObjectPlugin to my own project, renaming it to something else (UObjectPlugin2), then building my VS project. Doesn’t create the binaries for that plugin either. Definitely missing something.

I can take a look at it if you like. Could you share the whole project somewhere?