Creating Plugin with .lib and .dll

Hey there, I’m trying to create a plugin that uses some third party libraries. I followed this tutorial to set my plugin up: Unreal Engine: Including a Third-Party Library (on the example of the Point Cloud Library and Boost) [Tutorial] [Download] – Valentin Kraft's Portfolio
Unfortunately, I get the following error:

error C4273: “rsb::getFactory”:
Inconsistent dll linkage.

I placed my dlls in all possible folders. The plugins Binaries, the projects Binaries, and so on… but the error won’t dissapear. I linked all my .lib files as described in the tutorial and I think they can be found because I don’t get any errors with them.

I added the module in my plugins .Build.cs like this:

using UnrealBuildTool;

public class RSBInterface : ModuleRules
{
	public RSBInterface(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
		
		PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
                //"RSBInterface/Public"
			}
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
                "RSBInterface/Private",
                "RSBInterface/Public"
            }
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				// ... add other public dependencies that you statically link with here ...
                "RSBModule"
            }
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore"
				// ... add private dependencies that you statically link with here ...	
                
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

        // Since the PCL module needs this, we also have to use these flags here
        bUseRTTI = true;
        bEnableExceptions = true;
        //bEnableUndefinedIdentifierWarnings = false;
    }
}

And in my modules .Build.cs I included all the libs like this:

using System.IO;
using System;

using UnrealBuildTool;

public class RSBModule : ModuleRules
{
    private string ModulePath
    {
        get { return ModuleDirectory; }
    }

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

    public RSBModule(ReadOnlyTargetRules Target) : base(Target)
    {
        // Tell Unreal that this Module only imports Third-Party-Assets
        Type = ModuleType.External;

        LoadRSBModule(Target);
    }

    public bool LoadRSBModule(ReadOnlyTargetRules Target)
    {
        bool isLibrarySupported = false;
        //bool bDebug = (Target.Configuration == UnrealTargetConfiguration.Debug && BuildConfiguration.bDebugBuildsActuallyUseDebugCRT);

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

            string LibrariesPath = Path.Combine(ModulePath, "lib64");

            //string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";

            Console.WriteLine("... LibrariesPath -> " + LibrariesPath);
            Console.WriteLine("Test -> " + Path.Combine(LibrariesPath, "testfile"));

            // Explicitly name the used libraries
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "boost_atomic-vc141-mt-1_65_1" + ".lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "boost_atomic-vc141-mt-gd-1_65_1" + ".lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "boost_chrono-vc141-mt-1_65_1" + ".lib"));
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "boost_chrono-vc141-mt-gd-1_65_1" + ".lib"));
            ... [more libs]
        }

        if (isLibrarySupported)
        {
            PublicIncludePaths.Add(Path.Combine(ModulePath, "include"));

            Console.WriteLine("... IndlucePath -> " + Path.Combine(ModulePath, "include"));

            // Not sure if needed
            PublicDefinitions.Add("_CRT_SECURE_NO_WARNINGS=1");
            PublicDefinitions.Add("BOOST_DISABLE_ABI_HEADERS=1");

            // Needed configurations in order to run Boost
            bUseRTTI = true;
            bEnableExceptions = true;
            //bEnableUndefinedIdentifierWarnings = false;
        }

        PublicDefinitions.Add(string.Format("WITH_RSB_BINDING={0}", isLibrarySupported ? 1 : 0));
        PublicDefinitions.Add(string.Format("WITH_BOOST_BINDING={0}", isLibrarySupported ? 1 : 0));

        return isLibrarySupported;
    }
}

Is there anything I or the tutorial is missing?

UPDATE:
I have no idea if I’m right about that but I found out that usually the C4273 dll linkage error is a warning and that Unreal sometimes treats warning as errors. I can suppress this with #pragma warning(disable: 4273) but I don’t know if this is smart. However, when I try to compile with the error supressed, I get this error:

LINK : fatal error LNK1104: can not open file "xxxxx.lib"

I don’t know if there is something wrong with the path to this file, but I think not (I’m printing the include path and it is right). Does anyone have any experiences with this? I don’t really know where to look for answers…

Okay, lets break this down. There are following ways to implement dll/lib paired files.

  1. DLL with LIB.
  • Engine statically links to all functions
  • You have to use UBT to set things up
  • Your libraries are not exposed to end user
  • Linking is mendatory. Any missing references will throw error.
  1. DLL without LIB
  • Your code has function pointers
  • You have to use manually set things up
  • Your libraries are exposed to end user
  • Linking is optional. Any missing references will just continue the operation.

So, which one are planning to use ?

Thanks for your answer! I guess I have to go for the first way. The library I want to use in my plugin consists of libs, dlls and header files. If I am correct, I want to include the header files that are then using functions from the dll and lib files. I have found the following for linking dlls:

PublicDelayLoadDLLs.Add("XXXX.dll");

And that you can do something like this in your plugin’s cpp file:

DLLHandle = FPlatformProcess::GetDllHandle(*filePath);

But even with the PublicDelayLoadDLLs I am still getting this error. And since the DllHandle is in my cpp file and will be called in the ModuleStartup method I don’t think that this would solve my compile error. Am I right with this?