Problem with using C++ library in code

I’m pretty new to UE5 Development, and besides problems with my project dying several times from unknown conditions, i’ve run into a problem with using library. So to be short, i want to use Vosk voice recognition library, but whatever i try to do, it’s either won’t link at all (link errors), or simply successfully builds and tells me that “Patch could not be activated“. So, there is my code:

practice_2025.Build.cs

// Copyright Epic Games, Inc. All Rights Reserved.

using System;
using System.IO;
using UnrealBuildTool;

public class practice_2025 : ModuleRules
{
	public practice_2025(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(new string[]
		{
			"Core",
			"CoreUObject",
			"Engine",
			"InputCore",
			"Slate",
			"SlateCore",
			"UMG",
			"AudioCapture",
			"SignalProcessing",
			"AudioMixer"
		});

		// Library Path - 'practice_2025/ThirdParty/Vosk/'
		var VoskPath = Path.Combine(ModuleDirectory, "..", "..", "ThirdParty", "Vosk");

		// Header file (.h)
		PublicIncludePaths.Add(Path.Combine(VoskPath, "Include"));
		
		// Library file (.lib)
		PublicAdditionalLibraries.Add(Path.Combine(VoskPath, "Lib", "libvosk.lib"));
		
		// Runtime-dependencies(.dll)
		RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libvosk.dll"), StagedFileType.NonUFS);
		RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libstdc++-6.dll"), StagedFileType.NonUFS);
		RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libgcc_s_seh-1.dll"), StagedFileType.NonUFS);
		RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libwinpthread-1.dll"), StagedFileType.NonUFS);
		 
		PublicDelayLoadDLLs.Add("libvosk.dll");
		
		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			PublicDefinitions.Add("VOSK_EXPORT=__declspec(dllimport)");
		}
		
		PrivateDependencyModuleNames.AddRange(new string[] { });
	}
}

VoskListener.h

#pragma once

#include "CoreMinimal.h"
#include "VoskListener.generated.h"

struct VoskModel;
struct VoskRecognizer;

UCLASS()
class PRACTICE_2025_API AVoskListener : public AActor
{
	GENERATED_BODY()

public:
	AVoskListener();
	virtual ~AVoskListener();

	UFUNCTION(BlueprintCallable, Category = "Vosk")
	void InitVosk();

private:
	class FVoskInternal;
	FVoskInternal* VoskInternal;
	bool isRunning = false;
};

VoskListener.cpp

#include "VoskListener.h"
#include "vosk_api.h"

class AVoskListener::FVoskInternal
{
	public:
	VoskModel* Model = nullptr;
	VoskRecognizer* Recognizer = nullptr;
	
	float SampleRate = 16000.f;

	~FVoskInternal()
	{
		if (Model) vosk_model_free(Model);
		if (Recognizer) vosk_recognizer_free(Recognizer);
	}
};

AVoskListener::AVoskListener()
{
	VoskInternal = new FVoskInternal();
	InitVosk();
}

AVoskListener::~AVoskListener(){ delete VoskInternal; };

void AVoskListener::InitVosk()
{
	UE_LOG(LogTemp, Log, TEXT("Initializing Vosk..."))
	vosk_set_log_level(0);
	
	FString ModelPath = FPaths::Combine("..", "VoskModels", "rus");
	
	VoskInternal->Model = vosk_model_new(TCHAR_TO_UTF8(*ModelPath));
	VoskInternal->Recognizer = vosk_recognizer_new(VoskInternal->Model, VoskInternal->SampleRate);
	if (!VoskInternal->Model || !VoskInternal->Recognizer)
	{
		UE_LOG(LogTemp, Error, TEXT("Unable to load model or recognizer!"))
		return;
	}
	UE_LOG(LogTemp, Log, TEXT("General library components are loaded successfully!"))
}

So, currently it should be added to the level and just initialize model and recognizer objects, when this will be working i could make anything i want (stream recognition), but for now i don’t even have a single idea on how to fix this issue (was trying to debug it whole night but failed)

Hope anyone could help me, thank you in advance.

1 Like

hello denis, welcome.

can you post the actual log or error log?

1 Like

also if you’re new to ue i highly recommend to take some time to go over the basics. i’m sure they will help you as i see you have a couple of problems brewing in your code.

for example i think you’d benefit from having a subsystem instead of an actor. at least to initialize the lib.

keep in mind the constructor of actors runs on many different moments and you don’t control it.
i see you’ve made a plain class for vosks init and that seems good to me.

also consider using ue’s shared ptrs to help you out if needed.

i’ve never used vosk, but i’d recommend making sure it doesn’t use rtti or shared libc as that can cause issues.

1 Like

Sorry, should’ve add it too

Accepted Live coding shortcut
---------- Creating patch ----------
Running P:\UE_5.6\Engine\Build\BatchFiles\Build.bat -Target="practice_2025Editor Win64 Development -Project=""P:/code/practice_2025/practice_2025.uproject""" -LiveCoding -LiveCodingModules="P:/UE_5.6/Engine/Intermediate/LiveCodingModules.json" -LiveCodingManifest="P:/UE_5.6/Engine/Intermediate/LiveCoding.json" -WaitMutex -LiveCodingLimit=100
  Using bundled DotNet SDK version: 8.0.300 win-x64
  Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -Target="practice_2025Editor Win64 Development -Project=""P:/code/practice_2025/practice_2025.uproject""" -LiveCoding -LiveCodingModules="P:/UE_5.6/Engine/Intermediate/LiveCodingModules.json" -LiveCodingManifest="P:/UE_5.6/Engine/Intermediate/LiveCoding.json" -WaitMutex -LiveCodingLimit=100
  Log file: C:\Users\bukov\AppData\Local\UnrealBuildTool\Log.txt
  Using 'git status' to determine working set for adaptive non-unity build (P:\code\practice_2025).
  Parsing headers for practice_2025Editor
    Running Internal UnrealHeaderTool P:\code\practice_2025\practice_2025.uproject P:\code\practice_2025\Intermediate\Build\Win64\practice_2025Editor\Development\practice_2025Editor.uhtmanifest -WarningsAsErrors -installed
  Total of 0 written
  Reflection code generated for practice_2025Editor in 2.173446 seconds
  Building practice_2025Editor...
  Using Visual Studio 2022 14.38.33140 toolchain (P:\VisualStudio\IDE\VC\Tools\MSVC\14.38.33130) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).
  Determining max actions to execute in parallel (8 physical cores, 16 logical cores)
    Executing up to 8 processes, one per physical core
    Requested 1.5 GB memory per action, 2 GB available: limiting max parallel actions to 1
  Using Unreal Build Accelerator local executor to run 7 action(s)
    Storage capacity 40Gb
  ---- Starting trace: 250829_064809 ----
  UbaServer - Listening on 0.0.0.0:1345
  ------ Building 7 action(s) started ------
  [1/7] Compile [x64] BackgroundActor.cpp
  [2/7] Compile [x64] CameraPawn.cpp
  [3/7] Compile [x64] Module.practice_2025.gen.cpp
  [4/7] Compile [x64] PerModuleInline.gen.cpp
  [5/7] Compile [x64] TextDisplayWidget.cpp
  [6/7] Compile [x64] VoskListener.cpp
  [7/7] Compile [x64] practice_2025.cpp
  Trace written to file C:/Users/bukov/AppData/Local/UnrealBuildTool/Log.uba with size 4.4kb
  Total time in Unreal Build Accelerator local executor: 9.63 seconds
  
  Result: Succeeded
  Total execution time: 13.06 seconds
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\BackgroundActor.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\CameraPawn.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\Module.practice_2025.gen.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\PerModuleInline.gen.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\TextDisplayWidget.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\VoskListener.cpp.obj was modified or is new
File P:\code\practice_2025\Intermediate\Build\Win64\x64\UnrealEditor\Development\practice_2025\practice_2025.cpp.obj was modified or is new
Building patch from 7 file(s) for Live coding module P:\code\practice_2025\Binaries\Win64\UnrealEditor-practice_2025.dll
UbaCli v5.7.0-Uba_v1.0.0-43528563 (Rootdir: "C:\ProgramData\Epic\UbaCli", StoreCapacity: 0Gb)

---- Starting trace: Debugcfee3569-cddc-44bd-bd28-6a5450963967 ----
Running P:\VisualStudio\IDE\VC\Tools\MSVC\14.38.33130\bin\Hostx64\x64\link.exe @C:\Users\bukov\AppData\Local\Temp\9F9D.tmp
   Creating library P:\code\practice_2025\Binaries\Win64\UnrealEditor-practice_2025.patch_4.lib and object P:\code\practice_2025\Binaries\Win64\UnrealEditor-practice_2025.patch_4.exp
Detoured run took 1.0s
Successfully linked patch (0.000s)
Patch could not be activated.
---------- Finished (0.000s) ----------
1 Like

You are adding unnecessary complexity by using live coding.

What happens if you try it without live coding?

1 Like

It builds without any visible problems. Though, i think there is a low-level issue related to memory management that makes LiveCoding refuse the patch.

And about the LiveCoding, i tried to build straight from ide using compiler directly, there are still no visible changes in project or code-generated objects.

So it it builds without problems, what is the problem?

1 Like

It doesn’t update objects in UE5, there remains an old version that didn’t have anything to do with the library

+1

to compile without livecoding you have to disable it in the project settings, close the engine, delete intermediates and maybe saved, and compile with visual studio.

livecoding can seriously affect a dll.

what do you mean by that? i think john might be right. livecoding can end up creating other new names for classes when you import them.

If it’s possible that would make my life much easier :slight_smile: Weird i didn’t think of that myself.

It did exactly what the log said, built the source, but didn’t apply any changes to my c++ objects, that’s where the problem is.

i really struggle to understand what you mean.

nothing will change your cpp classes in code. you change the code yourself.

once you open the editor, changes should appear once compiled.

if you can’t see them either

  1. you’ve corrupted an instance by using livecoding (which can happen)
  2. it doesn’t have the correct UPROPERTY tag and metatag (eg readonly or readwrite or edit*)
  3. windows is being ~stu~windows and ignoring your files due to dates not being what it likes. this happens with perforce. you can try closing the engine, modifying the class a bit, (add an empty line), recompile.

There is no need to delete intermediates or saved

sometimes windows doesn’t update the cache correctly. if he’s having issues it might help to be sure.

1 Like

When i’m saying “c++ objects”, i reffer to these things in UE:

Okay, i’ve disabled the live coding, now it built successfully again, and ue5 gives this error (kill me pls):

” Unable to load the game module ‘practice_2025’. Probably OS error, module settings is incorrect or plugin is not included. “

It’s probably failing to load one of the dlls:

```
RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libvosk.dll"), StagedFileType.NonUFS);
RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libstdc++-6.dll"), StagedFileType.NonUFS);
RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libgcc_s_seh-1.dll"), StagedFileType.NonUFS);
RuntimeDependencies.Add(Path.Combine(VoskPath, "Binaries", "libwinpthread-1.dll"), StagedFileType.NonUFS);
```		 
Try adding all of them to PublicDelayLoadDLLs just to see if you can get the module to load
1 Like

is that like a popup message in a windows msgbox?
that means is not compiling.

can you try to compile through visual studio or find the actual log?