Build Error After Importing ONNX Runtime Library

Hi, I’m trying to import ONNX Runtime to UE4 to allow me to run ONNX AI models inside UE4. I get build errors however and would appreciate any help to rectify them.

To quickly detail my process, I add PrivateIncludePathModuleNames.AddRange(new string[] { "ORT" }); to my project’s build.cs file, thus, enabling the plugin. I have added the include headers, .libs, and .dlls from the ORT zip called onnxruntime-win-x64-1.10.0.zip to my plugins folder and added the following to my plugin’s build.cs file:

PublicIncludePaths.AddRange(
			new string[] {
				"$(PluginDir)\\" + "include"
			}
			);

		PublicAdditionalLibraries.AddRange(
			new string[] {
				"$(PluginDir)\\" + "LibraryBinaries\\" + "Windows\\" + "onnxruntime.lib",
				"$(PluginDir)\\" + "LibraryBinaries\\" + "Windows\\" + "onnxruntime_providers_shared.lib"
			}
			);

		PublicDelayLoadDLLs.AddRange(
			new string[] {
				"onnxruntime.dll",
				"onnxruntime_providers_shared.dll"
			}
			);

		RuntimeDependencies.Add("$(PluginDir)\\LibraryBinaries\\Windows\\onnxruntime.dll");
		RuntimeDependencies.Add("$(PluginDir)\\LibraryBinaries\\Windows\\onnxruntime_providers_shared.dll");

It builds correctly, but when I add #include <onnxruntime_cxx_api.h> to my main .cpp I get the following build error:

Build started...
1>------ Build started: Project: ImplementingONNX, Configuration: Development_Editor x64 ------
1>Building ImplementingONNXEditor...
1>Using Visual Studio 2019 14.29.30140 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
1>Building 4 actions with 24 processes...
1>  [1/4] TestingONNX.cpp
1>C:\Users\dmiln\UE4\ImplementingONNX\Plugins\ORT\include\onnxruntime_c_api.h(121): warning C4005: 'ORT_API': macro redefinition
1>  C:\Users\dmiln\UE4\ImplementingONNX\Intermediate\Build\Win64\UE4Editor\Development\ImplementingONNX\Definitions.ImplementingONNX.h(289): note: see previous definition of 'ORT_API'
1>  [2/4] UE4Editor-ImplementingONNX.lib
1>     Creating library C:\Users\dmiln\UE4\ImplementingONNX\Intermediate\Build\Win64\UE4Editor\Development\ImplementingONNX\UE4Editor-ImplementingONNX.lib and object C:\Users\dmiln\UE4\ImplementingONNX\Intermediate\Build\Win64\UE4Editor\Development\ImplementingONNX\UE4Editor-ImplementingONNX.exp
1>  [3/4] UE4Editor-ImplementingONNX.dll
1>     Creating library C:\Users\dmiln\UE4\ImplementingONNX\Intermediate\Build\Win64\UE4Editor\Development\ImplementingONNX\UE4Editor-ImplementingONNX.suppressed.lib and object C:\Users\dmiln\UE4\ImplementingONNX\Intermediate\Build\Win64\UE4Editor\Development\ImplementingONNX\UE4Editor-ImplementingONNX.suppressed.exp
1>TestingONNX.cpp.obj : error LNK2019: unresolved external symbol OrtGetApiBase referenced in function "void __cdecl `dynamic initializer for 'public: static struct OrtApi const * const Ort::Global<void>::api_''(void)" (??__E?api_@?$Global@X@Ort@@2PEBUOrtApi@@EB@@YAXXZ)
1>C:\Users\dmiln\UE4\ImplementingONNX\Binaries\Win64\UE4Editor-ImplementingONNX.dll : fatal error LNK1120: 1 unresolved externals
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(45,5): error MSB3073: The command ""C:\Program Files\Epic Games\UE_4.27\Engine\Build\BatchFiles\Build.bat" ImplementingONNXEditor Win64 Development -Project="C:\Users\dmiln\UE4\ImplementingONNX\ImplementingONNX.uproject" -WaitMutex -FromMsBuild" exited with code 6.
1>Done building project "ImplementingONNX.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The code on line 289 signified in the build error above is: #define ORT_API DLLIMPORT
The code at (45,5) signified in the build error above is: <Exec Command="$(NMakeBuildCommandLine)" Condition="'$(NMakeUseOemCodePage)' == 'true' and '$(NMakeBuildCommandLine)'!=''"/>

I’ve tried the suggestions at Error in c_cxx samples: unresolved external symbol "struct OrtApi const * const Ort::g_api" · Issue #2081 · microsoft/onnxruntime · GitHub, but these don’t help. I don’t implement the .pdb files, but I don’t think these are important are they?
Any suggestions on how to fix this are greatly appreciated, thanks so much

ONNX in Unreal 5

Do you have a working link for what you’re trying to provide please?


You can enable it by the plugins interface or compile from the source (you should be registered on EpicGame github). It’s for UE 5.0.0. Please check the UE version. Also exist for other versions

1 Like

Wow thanks so much, I hadn’t heard of this. Do you know of any docs for how to use it? I can’t seem to find any, maybe because it’s so new/in alpha?

I’ve found the docs: NeuralNetworkInference | Unreal Engine Documentation

Hopefully it becomes clearer how to use this plugin as time passes. Right now I’m not sure where to start!

I am waiting for tutorial :slight_smile: )
https://medium.com/@gineshidalgo99/nni-tutorial-how-to-officially-run-deep-learning-on-unreal-engine-5-445ad25f19cd
But also thinking to start using without it. Maybe next week - before I should prepare other stuff

Looks like this plugin you can use only in c++ mode or need additinal code for BP interactions.
The plugin allows import onnx model with one input (just drag and drop) but does not have any BP functions ;(

Thank you for the link! I’ll be waiting for that tutorial too. I also had a quick look at the plugin inside UE5 and, agreed, it looks like there’s minimal BP functionality :frowning: Please let me know if you make any progress using C++ and I’ll try do the same. What do you mean by just drag and drop? Drag and drop what where?

New tutorial out: Use ONNX Runtime and OpenCV with Unreal Engine 5 New Beta Plugins - YouTube

1 Like