Unreal can't load .lib file and gets stuck

Hi,
I’m trying to use my imitation.lib in a game demo project for my plugin here’s my build.cs for it :

public class ImitationLib : ModuleRules
{

	private string ModulePath
	{
		get { return ModuleDirectory; }
	}

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

	public ImitationLib(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
        bUseRTTI = true;
        bEnableExceptions = true;

        PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
			}
			);

		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				// ... add other public dependencies that you statically link with here ...
        "CoreUObject",
        "Engine",
        "InputCore",
        "HeadMountedDisplay",

				//added modules
				"SignalProcessing",
        "AudioMixer",
        "XmlParser",
				"AudioCapture",
        "UMG"
      }
			);

    PrivateIncludePaths.AddRange(
      new string[]
      {
        "ImitationLib/Public",
        "ImitationLib/Private/"
      }
      );

    PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
				"InputCore",
				"EditorStyle",
				// ... add private dependencies that you statically link with here ...	
				"AudioCapture"
      }
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

			//get platform target
			string Platform = Target.Platform.ToString();
			bool LibSupportedBool = false;

			//set a libSupportedBool if target platform is Win64
			if (Platform == "Win64")
                LibSupportedBool = true;
            else
                LibSupportedBool = false;

		PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "FreqAEC.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "imitation.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippcore.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippcoremt.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ipps.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippsmt.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippvm.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippvmmt.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippch.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "ippchmt.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "libfftw3f-3.lib"));
    PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib", "RingBufferLib.lib"));
    PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Include"));
    PublicDefinitions.Add(string.Format ("WITH_JUCE_BINDING={0}", LibSupportedBool ? 1 : 0 ) );
	}
}

So when I don’t use any function from my imitation.lib everything works fine but then when I use one function from it seems to load it indefinitely and gets stuck at 75% when I launch my vsSolution (because I use the predefault loading phase in my.uplugin I think) :

Adding an imitation.lib’s function and compiling it from the live coding console doesn’t work either and the console gets stuck at “Creating Patch Image” :

How are you calling the lib functions?

When accessing normal c++ with it’s includes are you using the correct switches to allow includes & third party content?


THIRD_PARTY_INCLUDES_START
// example includes
#include <windows.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>



#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#endif

/// custom code here

#if PLATFORM_WINDOWS
#include "Windows/HideWindowsPlatformTypes.h"
#endif


THIRD_PARTY_INCLUDES_END

You can’t just call your lib functions directly from unreal. You can expose them through static functions.

My AudioCaptureActor in my game needs to access MyCaptureComponent from my plugin :
image

MyCaptureComponent need to use one of the imitation lib’s function (here imi_trans_transform):

Here’s the header of MyCaptureComponent :

And here’s my ImitationLibPCH.h:

#pragma once

// Unreal
#include "Engine.h"
#include "AudioMixerDevice.h"
#include "Modules/ModuleManager.h"
#include "Internationalization/Internationalization.h"
#include "SlateBasics.h"
#include "GameFramework/Character.h"
#include "GameFramework/Actor.h"
#include "Components/ActorComponent.h"
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
#include "Logging/LogCategory.h"

// ImitationLib
THIRD_PARTY_INCLUDES_START
#include "ImitationTools.h"
#include "Muvoc/muvoc_system.h"
#include "Muvoc/imi_transform_rt.h"
#include "Muvoc/imi_trans_modes.h"
#include "Muvoc/muvoc_frequencyAEC.h"
#include "RingBuffer/RingBufferConsummer.h"
#include "RingBuffer/RingBufferNoLock.h"
#include "RingBuffer/RingBufferReadLock.h"
THIRD_PARTY_INCLUDES_END

#include "IImitationLib.h"
#include "AECFloat.h"

does imi_trans_transform call any standard library functions internally?
If so perhaps it’s execution should be isolated in it’s area.
I made a dll linker a while back where I had to push parts of the code to their own section for it to work ok with std

CreateAndLinkDLLTutBFL.zip (1.7 KB)

Yeah I think it does could you explain how can I use your Linker or if you have any use of case to give me ? (I don’t know if I was clear but my imitationLib (containing the imi_imi_transform symbol is a static lib so a .lib, not a dll)

The dll example is just to show how you can shift the execution of the function to a space that has the correct setup for sdt and windows.h type function execution if it’s needed for the functions internals.

I don’t think it’s right because I use strcpy() in my component which is a standard lib function and this works fine it’s just when I call a symbol from my imitationLib.lib that makes my editor crash so I’m not sure it’s linked to the fact that I use standard Lib functions

Could it maybe be a duplicate function name used in the lib? Unreal doesn’t normally allow the use if of namespaces so maybe it’s an already defined error that is triggered just silently?

Also the module itself has it’s own loading phase. if you set it to

"LoadingPhase": "Default",

then that might counteract the plugin loading phase or maybe it too has to match the preDefault? Not sure what the module is set at at the moment.

The module(ImitationLib plugin) is set at predefault

Perhaps another phase could work?


You could see if earlier phases change when the engine loading stops (other than 75%)

Also does you module cpp file use IMPLEMENT_MODULE & FDefaultModuleImpl?

IMPLEMENT_MODULE(FDefaultModuleImpl, IImitationLib);

there are no copy paste mistakes maybe by accident from the main project definition?

Changing the loading phase to earliestpossible just doesn’t launch the splashscreen of UE editor and post engine init just lock it at the same percentage (75)

And yeah, my Module cpp is fine :

#include "ImitationLib.h"


DEFINE_LOG_CATEGORY(LibLog);

#define LOCTEXT_NAMESPACE "FImitationLibModule"

FImitationLib::FImitationLib()
{
	
}

void FImitationLib::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
	UE_LOG(LibLog, Warning, TEXT("ImitationLib: Log Started"));
}

void FImitationLib::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
	UE_LOG(LibLog, Warning, TEXT("ImitationLib: Log Ended"));
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FImitationLib, ImitationLib)

This is so frustrating like there is no log of nothing it just freezes because of my .lib but no clue of why it would do that when there was no problem implementing it in other software

Unreal in some cases will actually stop loading at 75% due to un-compiled or corrupt blueprint actors. It’s a bit stupid. There should be more information to why it stops loading.

I’ll try moving my plugin to a blank project and see if this was the issue

Yeah on a blank project it gets stuck at 90% I’m pretty sure it’s still the step where the editor loads the plugin

Maybe try different loading phases on the fresh project

Up my includes are correctly guarded by include “AllowWindowsPlatformTypes.h”
but it’s still doesn’t work

Hmm seeing as there is no direct information from the editor then maybe add a try catch statement inside of your library function call (make it silent so no throwing) and try saving out the error message to a file.

Or see it the try catch is triggered with a breakpoint on load?

So Something like that ? (the functions of my .lib begins with imi_) :

void UMyCaptureComponent::SetImitationDirectory(FString targetName)
{
	try {
		UE_LOG(LogTemp, Warning, TEXT("SetImitationDirectory: %s"), *GetModelPath(targetName));

		//add try and catch to check if the function of the .lib is loaded
		if (!m_imiHandle)
			imi_trans_delete(m_imiHandle);

		strcpy_s(m_imiParams.voice_dir, TCHAR_TO_ANSI(*GetModelPath(targetName)));


		imi_number_of_trans_handle(1);

		m_imiHandle = 0;
		/** Constructor for the zero delay method */
		imi_trans_zd_new(m_imiHandle, &m_imiParams, mSampleRate, mSampleRate);
	}
	catch (const std::exception& e)
	{
		FString ErrorMessage = FString::Printf(TEXT("Exception caught: %s"), UTF8_TO_TCHAR(e.what()));

		// Write error message to log file
		FString LogFilePath = FPaths::ProjectLogDir() + TEXT("ExceptionLog.txt");
		FFileHelper::SaveStringToFile(ErrorMessage, *LogFilePath);

		UE_LOG(LogTemp, Error, TEXT("%s"), *ErrorMessage);
	}
	catch (...)
	{
		// Catch any other exceptions
		FString ErrorMessage = TEXT("Unknown exception caught in SetImitationDirectory");

		// Write error message to log file
		FString LogFilePath = FPaths::ProjectLogDir() + TEXT("ExceptionLog.txt");
		FFileHelper::SaveStringToFile(ErrorMessage, *LogFilePath);

		UE_LOG(LogTemp, Error, TEXT("%s"), *ErrorMessage);
	}
}

Give it a test. I know that unreal normally ommits try / catch but see if the debugger is triggered by it.