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