Download

Trying to follow Linking Static Libraries tutorial

I’m following this guide, https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System, trying to integrate the sixense sdk available from http://sixense.com/hardware/sixensesdk. I had done this previously using dllbind in UDK and now wish to migrate to UE4.

However, the guide is a bit hard for me to follow as to which files are in which directory. If I’m understanding correctly, I should have something like:

(ProjectFolder)UESixense/ThirdParty/MyThirdParty(Sixense)/LibSX_01/Includes/sixense.h(provided header)

(ProjectFolder)UESixense/ThirdParty/MyThirdParty(Sixense)/LibSX_01/Libraries/sixense_s_x64.lib (lib file)

(ProjectFolder)UESixense/Source/(ProjectName)UESixense/UESixense.Build.cs(build file) Then header in /Public and .cpp in /Private

Ultimately, when I try to compile, I get
“LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup”

Which are in reference to UE4Editor-SixenseUE4.dll

Ok, I still get “LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup”
It seems to be refusing to produce my game module .dll

Is this a problem with the .lib I am linking? Commenting out these lines still presents the error.



//PublicAdditionalLibraries.Add(LibraryName + ".lib");


UESixense.Build.cs




using UnrealBuildTool;
using System.IO;

public class UESixense : ModuleRules
{

    private string ModulePath
    {
        get { return Path.GetDirectoryName(UnrealBuildTool.RulesCompiler.GetModuleFilename(this.GetType().Name)); }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
    }

    public UESixense(TargetInfo Target)
    {
        LoadSixense(Target);
    }


    public bool LoadSixense(TargetInfo Target)
	{	
        bool isLibrarySupported=false;
		
		/** Mark the current version of the Sixense SDK */
		Type = ModuleType.External;

		if ((Target.Platform == UnrealTargetPlatform.Win64) ||
			(Target.Platform == UnrealTargetPlatform.Win32))
		{
            isLibrarySupported=true;

            string LibraryPath = ThirdPartyPath + "Sixense/LibSX_01/Libraries/";
            string IncludePath = ThirdPartyPath + "Sixense/LibSX_01/Includes/";

			string LibraryName = "sixense_s";
			if (Target.Platform == UnrealTargetPlatform.Win64)
			{
				LibraryName += "_x64";
			}
            else if (Target.Platform == UnrealTargetPlatform.Win32)
            {
			
            }

            Definitions.Add(string.Format("SIXENSE_LIB_PATH=\"\"{0}\"\"", Path.Combine(LibraryPath, LibraryName + ".lib")).Replace("\\", "\\\\"));
            
			PublicLibraryPaths.Add(LibraryPath);
			PublicIncludePaths.Add(IncludePath);
			PublicAdditionalLibraries.Add(LibraryName + ".lib");
			//PublicDelayLoadDLLs.Add(LibraryName + ".dll");

            Definitions.Add(string.Format( "WITH_SIXENSE_BINDING={0}", isLibrarySupported ? 1 : 0 ) );
			
			
		}

        return isLibrarySupported;
	}
}


UESixense.cpp




#include "Welcome/to/sixense.h"

#include "UESixense.h"

#include "UESixense.generated.inl"

#pragma comment(lib, SIXENSE_LIB_PATH) // Include Bobs Magic Library

class FUESixenseGameModule : public FDefaultGameModuleImpl
{
	Sixense::MoSixense *PointerToSixense;

	/**
	* Called right after the module DLL has been loaded and the module object has been created
	*/
	virtual void StartupModule() OVERRIDE
	{
		PointerToSixense = new Sixense::MoSixense();

		PointerToSixense->ThankEveryoneForReading();
	}

	/**
	* Called before the module is unloaded, right before the module object is destroyed.
	*/
	virtual void ShutdownModule()
	{
		PointerToSixense->Dispose();
		PointerToSixense = NULL;
	}
};

// Override the default implementation with ours implementation =)
IMPLEMENT_PRIMARY_GAME_MODULE(FUESixenseGameModule, UESixense, "UESixense");


UESixense.h




#include "Engine.h"

UCLASS()
class FUESixense : public FDefaultGameModuleImpl
{
	GENERATED_UCLASS_BODY()

	virtual void StartupModule() OVERRIDE;

	virtual void ShutdownModule();
};



EDIT: Nevermind, I got it. It wasn’t related to the static linking, I an error in my module creating process :slight_smile:
Thanks for the great tutorials, Rama

I have trouble following that tutorial. Can someone give me a clear explanation on directory structure: where are the paths based from? Also the build.cs in the tutorial is in bits and pieces, I am not sure where things are supposed to go. Anyone have a complete UE4Magic.build.cs for that tutorial?

I have been trying to link in a library, but the path to my .lib is always wrong. I even used ProcMon to check which paths were being search during build, and it seemed to go look for the .lib in the Unreal Engine directories instead of my project directories.

Ok I got it, my mistake was trying to put relative paths without using the convenience functions, which provide full paths.

Is it normal that Intellisense stops working when I add third-party libraries? Also, unless I rebuild the solution completely, I get a bunch of unresolved references for FVector::ZeroVector



LogMainFrame: MainFrame: Module compiling took 4.520 seconds
CompilerResultsLog: New page: Compilation - Apr 6, 2014, 7:12:27 AM
CompilerResultsLog: Info Parsing headers for MyProject5
CompilerResultsLog: Info Code generation finished for MyProject5 and took 1.822
CompilerResultsLog: Info link.exe UE4Editor-MyProject5-9662.dll
CompilerResultsLog:Error: Error TestPawn.cpp.obj : error LNK2001: unresolved external symbol "public: static class FVector const FVector::ZeroVector" (?ZeroVector@FVector@@2V1@B)
CompilerResultsLog:Error: Error MyProject5.h.obj : error LNK2001: unresolved external symbol "public: static class FVector const FVector::ZeroVector" (?ZeroVector@FVector@@2V1@B)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "public: static class FVector const FVector::ZeroVector" (?ZeroVector@FVector@@2V1@B)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "public: static class FVector const FVector::ZeroVector" (?ZeroVector@FVector@@2V1@B)
CompilerResultsLog:Error: Error MyProject5PlayerController.cpp.obj : error LNK2001: unresolved external symbol "public: static class FVector const FVector::ZeroVector" (?ZeroVector@FVector@@2V1@B)
CompilerResultsLog:Error: Error GameGeneratedActor.cpp.obj : error LNK2001: unresolved external symbol "bool GCycleStatsShouldEmitNamedEvents" (?GCycleStatsShouldEmitNamedEvents@@3_NA)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "bool GCycleStatsShouldEmitNamedEvents" (?GCycleStatsShouldEmitNamedEvents@@3_NA)
CompilerResultsLog:Error: Error GameGeneratedActor.cpp.obj : error LNK2001: unresolved external symbol "private: static bool FThreadStats::bMasterEnable" (?bMasterEnable@FThreadStats@@0_NA)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "private: static bool FThreadStats::bMasterEnable" (?bMasterEnable@FThreadStats@@0_NA)
CompilerResultsLog:Error: Error GameGeneratedActor.cpp.obj : error LNK2001: unresolved external symbol "private: static unsigned int FThreadStats::TlsSlot" (?TlsSlot@FThreadStats@@0IA)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "private: static unsigned int FThreadStats::TlsSlot" (?TlsSlot@FThreadStats@@0IA)
CompilerResultsLog:Error: Error GameGeneratedActor.cpp.obj : error LNK2001: unresolved external symbol "struct FLogCategoryLogClass LogClass" (?LogClass@@3UFLogCategoryLogClass@@A)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "struct FLogCategoryLogClass LogClass" (?LogClass@@3UFLogCategoryLogClass@@A)
CompilerResultsLog:Error: Error GameUtils.cpp.obj : error LNK2001: unresolved external symbol "struct FLogCategoryLogClass LogClass" (?LogClass@@3UFLogCategoryLogClass@@A)
CompilerResultsLog:Error: Error MyProject5PlayerController.cpp.obj : error LNK2001: unresolved external symbol "struct FLogCategoryLogClass LogClass" (?LogClass@@3UFLogCategoryLogClass@@A)
CompilerResultsLog:Error: Error GameGeneratedActor.cpp.obj : error LNK2001: unresolved external symbol "struct FThreadSafeStaticStat<struct FStat_STAT_GetComponentsTime> StatPtr_STAT_GetComponentsTime" (?StatPtr_STAT_GetComponentsTime@@3U?$FThreadSafeStaticStat@UFStat_STAT_GetComponentsTime@@@@A)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "public: static class FColor const FColor::Blue" (?Blue@FColor@@2V1@B)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "class FUObjectArray GUObjectArray" (?GUObjectArray@@3VFUObjectArray@@A)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "public: static struct FKey const EKeys::LeftMouseButton" (?LeftMouseButton@EKeys@@2UFKey@@B)
CompilerResultsLog:Error: Error GameHUD.cpp.obj : error LNK2001: unresolved external symbol "public: static struct FKey const EKeys::RightMouseButton" (?RightMouseButton@EKeys@@2UFKey@@B)
CompilerResultsLog:Error: Error GameUtils.cpp.obj : error LNK2001: unresolved external symbol "public: static struct FVector2D const FVector2D::ZeroVector" (?ZeroVector@FVector2D@@2U1@B)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "enum ENamedThreads::Type ENamedThreads::RenderThread" (?RenderThread@ENamedThreads@@3W4Type@1@A)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "bool GIsThreadedRendering" (?GIsThreadedRendering@@3_NA)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "bool GMainThreadBlockedOnRenderThread" (?GMainThreadBlockedOnRenderThread@@3_NA)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "public: static class FName const UCollisionProfile::BlockAllDynamic_ProfileName" (?BlockAllDynamic_ProfileName@UCollisionProfile@@2VFName@@B)
CompilerResultsLog:Error: Error GeneratedMeshComponent.cpp.obj : error LNK2001: unresolved external symbol "public: static class FVertexFactoryType FLocalVertexFactory::StaticType" (?StaticType@FLocalVertexFactory@@2VFVertexFactoryType@@A)
CompilerResultsLog:Error: Error MyProject5.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl UELinkerFixups(void)" (?UELinkerFixups@@YAXXZ) referenced in function "void __cdecl UELinkerFixupCheat(void)" (?UELinkerFixupCheat@@YAXXZ)
CompilerResultsLog:Error: Error MyProject5.cpp.obj : error LNK2001: unresolved external symbol "public: static class TBaseDelegate_RetVal_NoParams<int * * *> FCoreDelegates::GetSerialNumberBlocksDebugVisualizers" (?GetSerialNumberBlocksDebugVisualizers@FCoreDelegates@@2V?$TBaseDelegate_RetVal_NoParams@PEAPEAPEAH@@A)
CompilerResultsLog:Error: Error MyProject5.cpp.obj : error LNK2001: unresolved external symbol "public: static class TBaseDelegate_RetVal_NoParams<class TArray<class UObjectBase *,class FDefaultAllocator> *> FCoreDelegates::ObjectArrayForDebugVisualizers" (?ObjectArrayForDebugVisualizers@FCoreDelegates@@2V?$TBaseDelegate_RetVal_NoParams@PEAV?$TArray@PEAVUObjectBase@@VFDefaultAllocator@@@@@@A)
CompilerResultsLog:Error: Error MyProject5.cpp.obj : error LNK2001: unresolved external symbol "class FUObjectAllocator GUObjectAllocator" (?GUObjectAllocator@@3VFUObjectAllocator@@A)
CompilerResultsLog:Error: Error C:\dev\Unreal\Projects\MyProject5\Binaries\Win64\UE4Editor-MyProject5-9662.dll : fatal error LNK1120: 20 unresolved externals
CompilerResultsLog: Info -------- End Detailed Actions Stats -----------------------------------------------------------
CompilerResultsLog: Info ERROR: UBT ERROR: Failed to produce item: C:\dev\Unreal\Projects\MyProject5\Binaries\Win64\UE4Editor-MyProject5-9662.dll
CompilerResultsLog:Error: Error Cumulative action seconds (8 processors) : 0.00 building projects, 0.00 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.10 linking, 0.00 other
CompilerResultsLog: Info UBT execution time: 4.45 seconds
Warning: HotReload failed, recompile failed


someone can help me with that…

actually i have this: a include file called hardware.h inside the source/thirdparty/includes, and a .lib file inside source/ThirdParty/libraries, compiled in x64, i guess with the proper options

then i have this:
//UE4CHardware.cs

using UnrealBuildTool;
using System.IO;
public class UE4CHardware : ModuleRules
{
public UE4CHardware(TargetInfo Target)
{
LoadCHardware(Target);
}
public bool LoadCHardware(TargetInfo Target)
{
bool isLibrarySupported = false;
string libraryPath = “C:\Users\JorgeCR\Documents\Unreal Projects\TestDll\Source\ThirdParty\libraries\”;
string includePath = “C:\Users\JorgeCR\Documents\Unreal Projects\TestDll\Source\ThirdParty\includes\”;
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
isLibrarySupported = true;

        PublicAdditionalLibraries.Add(Path.Combine(libraryPath, "hardware." + ".lib"));
    }

    if (isLibrarySupported)
    {
        PublicIncludePaths.Add(includePath);
    }

    Definitions.Add(string.Format("WITH_CHWARDWARE_BINDING={0}", isLibrarySupported ? 1 : 0));

    return isLibrarySupported;

}

}

at this point i compile and everything is fine, no errors!!!.
but the problem is when i try the linking with UE4
i try this for my header:
//UECHardware.h
#pragma once
#include “Engine.h”

UCLASS()
class UECHardware : public FDefaultGameModuleImpl
{
GENERATED_UCLASS_BODY()

virtual void StartupModule() OVERRIDE;

virtual void ShutdownModule();

};

and my cpp
//UECHardware.cpp

#include “UECHardware.h”
#include “UECHardware.generated.inl”
#include “hardware.h”
#pragma comment (lib,CHARDWARE_LIB_PATH)

class UECHardwareModule : public FDefaultGameModuleImpl
{
hardwareNS::VWHardware *PointerToVWHardware;

virtual void StartupModule() OVERRIDE
{
	PointerToVWHardware = new hardwareNS::VWHardware();

}


virtual void ShutdownModule()
{
	PointerToVWHardware-&gt;Dispose();
	PointerToVWHardware = NULL;
}

};

IMPLEMENT_PRIMARY_GAME_MODULE(UECHardwareModule, UECHardware, “UECHardware”);

its compile but i dont know where is the location for this files, rama say that are inside the ThirdParty directory, i dont thick so, because VS not recognizes my #includes and of course nothing more about that.

someone pliss help me with the link!! i am lost

I updated the wiki page to include a “Review” section at the bottom, which basically encapsulates an illustration that shows what I set up in order to make this work.

I hope it helps:

https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System#Review
UnrealDLL_Builds.jpg