I want to use the prebuilt onnxruntime library with cmake in c++. This my directory structure:
/root/externals/onnxruntime/include
/root/externals/onnxruntime/lib
/root/CMakeLists.txt
/root/main.cpp
The header files are in the include folder and in the lib folder are *.lib, *.dll, *.pdb files.
This is the CMakeLists.txt, I wrote:
cmake_minimum_required(VERSION 3.13)
project(myproject VERSION 0.1.0 LANGUAGES C CXX)
add_executable(myproject main.cpp)
set(ONNXRUNTIME_ROOTDIR ${CMAKE_SOURCE_DIR}/externals/onnxruntime)
find_library(myonnxruntimelib onnxruntime NAME onnxruntime HINTS
${CMAKE_SOURCE_DIR}/externals/onnxruntime/lib)
if(${myonnxruntimelib} STREQUAL myonnxruntimelib-NOTFOUND)
message(FATAL_ERROR "onnxruntime not found")
else()
message(STATUS "onnxruntime found as ${myonnxruntimelib}")
endif()
include_directories("${ONNXRUNTIME_ROOTDIR}/include")
target_link_libraries(myproject ${myonnxruntimelib})
The find_library() finds the *.lib file correctly, but when I build it, it gives these errors:
main.obj : error LNK2019: unresolved external symbol _OrtGetApiBase@0 referenced in function "void __cdecl `dynamic initializer for 'public: static struct OrtApi const * const Ort::Global< void>::api_''(void)" (??__E?api_@?$Global@X@Ort@@2PBUOrtApi@@B@@YAXXZ)
[C:\root\build\myproject.vcxproj] C:\root\externals\onnxruntime\lib\onnxruntime.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86' [C:\root\build\myproject.vcxproj]
C:\root\build\Debug\myproject.exe : fatal error LNK1120: 1 unresolved externals [C:\root\build\myproject.vcx proj]
Done Building Project "C:\root\build\myproject.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\root\build\myproject.vcxproj" (default target) (1) ->(Link target) ->
C:\root\externals\onnxruntime\lib\onnxruntime.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86' [C:\root\build\myproject.vcxproj]
"C:\root\build\myproject.vcxproj" (default target) (1) ->(Link target) ->
main.obj : error LNK2019: unresolved external symbol _OrtGetApiBase@0 referenced in function "void __cdecl `dynamic initializer for 'public: static struct OrtApi const * const Ort::Global<void>::api_''(void)" (??__E?api_@?$Global@X@Ort@@2PBUOrtApi@@B@@YAXXZ)
[C:\root\build\myproject.vcxproj]C:\root\build\Debug\myproject.exe : fatal error LNK1120: 1 unresolved externals [C:\root\build\myproject.v cxproj]
1 Warning(s)
2 Error(s)
Moreover, onnxruntime.lib file has this structure
Any hint how this issue can be resolved?