help with linking static libs (tutorial seems incomplete)

Hey, I’m having some trouble trying to include the dll I made to the build process.

I followed this tutorial to the best of my ability, but its not very clear.

To recap, I included the dll and .lib at:



carGame\ThirdParty\LogitechSteeringWheel\Libraries


and the header file here:



carGame\ThirdParty\LogitechSteeringWheel\Includes


I have a build file here:



carGame\Source\LogitechSteeringWheel\LogitechSteeringWheel.Build.cs


that looks like:
(I started to comment out code sine the original stuff wasn’t working)



using System.IO;
using System;

namespace UnrealBuildTool.Rules
{
	public class LogitechSteeringWheel : ModuleRules
	{
		private string ModulePath
		{
			get { return Path.GetDirectoryName( RulesCompiler.GetModuleFilename( this.GetType().Name ) ); }
		}
	 
		private string ThirdPartyPath
		{
			get { return Path.GetFullPath( Path.Combine( ModulePath, "../../ThirdParty/" ) ); }
		}
	 
		public LogitechSteeringWheel(TargetInfo Target)
		{
			//[Standard Module Initialization]//what is this supposed to be??????
	 
			LoadLogitechSteeringWheel(Target);
		}
		
		public bool LoadLogitechSteeringWheel(TargetInfo Target)
		{
			bool isLibrarySupported = false;
	 
			//if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
			{
				isLibrarySupported = true;
	 
				string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
				string LibrariesPath = Path.Combine(ThirdPartyPath, "LogitechSteeringWheel", "Libraries");
	 
				//TODO: get differnt versions working 
				//PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "LogitechSteeringWheel." + PlatformString + ".lib")); 
				PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "LogitechSteeringWheel.lib")); 
				Console.WriteLine("path = " + LibrariesPath);
			}
	 
			if (isLibrarySupported)
			{
				// Include path
				PublicIncludePaths.Add( Path.Combine( ThirdPartyPath, "LogitechSteeringWheel", "Includes" ) );
			}
	 
			Definitions.Add(string.Format( "WITH_LOGITECH_STEERINGWHEEL_BINDING={0}", isLibrarySupported ? 1 : 0 ) );
	 
			return isLibrarySupported;
		}
	}
}


but, i still get linker errors. What am I missing? I can see I’m not the only one confused by the build system, so lets get this figured out once and for all

Thanks

For [Standard Module Init] I have PublicDependencyModuleNames.AddRange(new string] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “RHI”, “RenderCore”, “ShaderCore” }); although you probably won’t need the last 3 modules in that list.

What is the link error, your paths look to be the same as mine.

Thanks for the reply.

The error I’m getting is the standard “error LNK2019: unresolved external symbol” that shows the decorated function call Im trying to use from the dll. If this was a “normal” visual studio build process, I would just make sure that the lib file and the lib file directory were in the project options. Seeing as the c# files are supposed to do that, I cant tell if the build process is looking in the wrong area, or what.

I also added the PublicDependencyModuleNames line in the cs file, but it didnt help the situation.

I have a feeling, its just something small I’m missing, but I dont know the build system well, and I cant seem to find the exact info i need.

Oh yeah, is there a way to use console output to debug the c# files? This could help to make sure things are at least being set as intended.

Hi,Boy. do you check your lib is linked with 2013(the same your game)

Yeah, I made the lib myself, and I made sure to make it with visual studio 2013.

I also tested the lib in a stand alone project, and I verified that it works.

Is LogitechSteeringWheel your primary game module? Or is it just a dependency module? There are two ways to go about this, you can hard-code the static-lib into your primary game module like the tutorial does, or you can create a module that sets up the include paths, library paths and preprocessor definitions for your static lib, and then set that module as a dependency of your primary game module. I much prefer the second approach.

hmmm, where can I get more info about the 2nd approach?

Also, where are the log files from the build process stored?

Most if not all third party libraries in the engine source are setup like this, have a look in Engine/Source/ThirdParty (Vorbis for instance).

If you’re building the engine then they should be under Engine/Intermediate/Build/Unused, not sure about building game projects. UHT logs are under Engine/Programs/UnrealHeaderTool/Saved/Logs

Im getting the same errors. :confused:

I also noticed that while my biuld.cs files are being compiled (I know this because if I make a syntax error in the build.cs file, I get the proper errors). However, when things build, I know none of the code is being used because I have this line:



string IncludePath = UEBuildConfiguration.UEThirdPartySourceDirectory+"LogitechSteeringWheel/Includes/";
PublicIncludePaths.Add(IncludePath);


and visual studio and the build process complains about not finding the header file. Its only when goto project properties -> VC++ Directories -> Include Directories and put in the path the header file can be found and used. (I also tried to use the same “fix” with Library Directories, but it didnt help.)

I also noticed that if i tried to #include another 3rd party lib header file (vorbisfile.h or OVR.h for example) it cant find those #include paths either. This tells me that something simple is not set up properly. I just need to find whatever is missing.

Did you add the relevant module to the PrivateDependencyModuleNames in your project’s Build.cs?

I have PublicDependencyModuleNames, it looks like this:



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


should i change it to PrivateDependencyModuleNames?

[note, i have no idea what PrivateDependencyModuleNames or PublicDependencyModuleNames do or what they are used for :rolleyes:]

[edit] here is everything:

my new cs build file, located:
C:\Program Files\Unreal Engine\4.4\Engine\Source\ThirdParty\LogitechSteeringWheel



using System.IO;
using System;
using UnrealBuildTool;


public class LogitechSteeringWheel : ModuleRules
{
	public LogitechSteeringWheel(TargetInfo Target)
	{
		Type = ModuleType.External;
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });
		
		string LibraryPath = UEBuildConfiguration.UEThirdPartySourceDirectory+"LogitechSteeringWheel/Libraries/";
		string IncludePath = UEBuildConfiguration.UEThirdPartySourceDirectory+"LogitechSteeringWheel/Includes/";
		
		//string LibraryPath = @"C:\Program Files\Unreal Engine\4.4\Engine\Source\ThirdParty\LogitechSteeringWheel\Libraries";
		//string IncludePath = @"C:\Program Files\Unreal Engine\4.4\Engine\Source\ThirdParty\LogitechSteeringWheel\Includes";
		
		string LibraryName = "LogitechSteeringWheel";

		PublicLibraryPaths.Add(LibraryPath);
		PublicIncludePaths.Add(IncludePath);
		PublicAdditionalLibraries.Add(LibraryName + ".lib");
		
		 Definitions.Add(string.Format("WITH_SIXENSE_BINDING=1" ));
	}
}


here is my error (adding it to the vehicle template made with c++. I added the header and the init() to the HUD c++ file.)



1>------ Build started: Project: carTest, Configuration: DebugGame_RocketGame x64 ------
1>  Performing 1 actions (max 2 parallel jobs)
1>  [1/1] link.exe carTest-Win64-DebugGame.exe
1>     Creating library K:\Unreal Projects\carTest\Binaries\Win64\carTest-Win64-DebugGame.lib and object K:\Unreal Projects\carTest\Binaries\Win64\carTest-Win64-DebugGame.exp
1>carTestHud.cpp.obj : error LNK2019: unresolved external symbol "public: static void __cdecl SteeringWheel::initSteeringWheel(void)" (?initSteeringWheel@SteeringWheel@@SAXXZ) referenced in function "public: __cdecl AcarTestHUD::AcarTestHUD(class FPostConstructInitializeProperties const &)" (??0AcarTestHUD@@QEAA@AEBVFPostConstructInitializeProperties@@@Z)
1>K:\Unreal Projects\carTest\Binaries\Win64\carTest-Win64-DebugGame.exe : fatal error LNK1120: 1 unresolved externals
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: K:\Unreal Projects\carTest\Binaries\Win64\carTest-Win64-DebugGame.exe
1>  Cumulative action seconds (4 processors): 0.00 building projects, 0.00 compiling, 0.00 creating app bundles, 0.00 generating debug info, 4.12 linking, 0.00 other
1>  UBT execution time: 8.40 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Unreal Engine\4.4\Engine\Build\BatchFiles\Build.bat" carTest Win64 DebugGame "K:\Unreal Projects\carTest\carTest.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


No, I should’ve been more clear, I meant the PrivateDependencyModuleNames in the Build.cs of your game project (carTest.Build.cs I guess)

Every bit of functionality in the engine or any game project is encapsulated in a module, to use any of that functionality you need to let the Unreal Build Tool know which modules your code needs so that it can setup the include and library directories properly when generating the Visual Studio projects and when building your project. Now, if you specify module B in PublicDependencyModuleNames of module A then any other module that depends on module A will also be able to access the functionality in module B (without explicitly specifying that dependency). In contrast if you add module B to PrivateDependencyModuleNames of module A then only the code in module A will be able to access the functionality in module B.

I didnt have that line in the game’s build.cs file. I tried to add it,and I got an error (the methods arent members of TargetRules or whatever). I see that the build script for the game and the 3rd party stuff inherit from different classes (which would explain the error) So, I tried to find the base class for each the modulerules and the TargetRules, but I dont have the dir that this ue4 answer specifies.

Also, I dont have the dir for the logs that you mentioned a few posts above. Doing window searches for both the base class stuff and the log files didnt bring back what i was looking for. :confused:

…Wait a minute…is the only way to do what I’m trying to do is build ue4 from the source, and not install it via the installer?

[/QUOTE]

Thanks for this explanation, it really does clear some things up. :cool:

You’ve tried modifying one of the .Target.cs file for your project, there should be no need to mess with it, you need to modify the .Build.cs. The .Target.cs files are in the Source folder of your project, the .Build.cs is one level down (probably in Source/carTest). That Answerhub question is not relevant to what you’re doing here.

Hmm, maybe poke around in the Intermediate folder of your project then, I’m working in the engine source right now and don’t have a built code-based project at hand.

You don’t need the engine source, but if you’re working with the installer/launcher version you’ll probably need to put all your modules in your project’s Source directory as opposed to the engine’s third party source directory. It should probably look like this:



carTest/
    Source/
        carTest/
        LogitechSteeringWheel/


You’ll need to update the steering wheel Build.cs with the correct paths if you move it into your project Source directory, use the ModulePath (look in the .Build.cs in your first post) to build the correct include/lib paths.

This was it!! Once I added the lib path in the games build. cs file, it was able to find the lib. (i have other errors now, lol, but they are much easier to understand and fix!)

Thanks so much for your patience! I will update this post once i verify that every thing works, and hopefully, I can add more info to the wiki answer to help others as well.

hey guys,

I have created a whole tutorial on how to include third-party libraries into unreal with a custom plugin. I have an extra section for linking static libs. Have a look here: How to include Third Party library (like boost / PCL) in a custom plugin? [SOLVED] - Plugins - Epic Developer Community Forums