Cross compile tvm_runtime_pack.cc

Hi all,

against my will, I will have to deploy some models on Windows machines. So I’m trying to cross compile my current c++ code using minGW and using cmake. The way I’m currently deploying the models is by including in the sources of the project tvm_runtime_pack.cc as suggested by the community, but I’m having some problems during both compilation and link times.

At compilation time I only get a lot of warnings like this one:

In file included from /home/ds017/test/src/Impl/tvm_runtime_pack.cc:40:0:
/home/ds017/test/src/Impl/../../../tvm/src/runtime/c_runtime_api.cc: In function ‘std::__cxx11::string tvm::runtime::GetCustomTypeName(uint8_t)’:
/home/ds017/test/src/Impl/../../../tvm/src/runtime/c_runtime_api.cc:48:13: warning: ‘std::__cxx11::string tvm::runtime::GetCustomTypeName(uint8_t)’ redeclared without dllimport attribute after being referenced with dll linkage
 std::string GetCustomTypeName(uint8_t type_code) {

At link time instead I get a lot of undefined errors:

CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x268b): undefined reference to `__imp__ZN3tvm7runtime6Module12LoadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x2cac): undefined reference to `__imp__ZN3tvm7runtime8Registry3GetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x5d32): undefined reference to `__imp_TVMArrayAlloc'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x5d4e): undefined reference to `__imp_TVMArrayCopyFromBytes'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x5f7c): undefined reference to `__imp_TVMArrayFree'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x612f): undefined reference to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x6153): undefined reference to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x6177): undefined reference to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x619c): undefined reference to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x63dd): undefined reference to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv'
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text+0x6401): more undefined references to `__imp__ZNK3tvm7runtime7NDArray8ToDLPackEv' follow
CMakeFiles/test_lib.dir/objects.a(test2.cpp.obj):test2.cpp:(.text$_ZN3tvm7runtime11TVMRetValue5ClearEv[_ZN3tvm7runtime11TVMRetValue5ClearEv]+0x72): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x125): undefined reference to `__imp_TVMArrayAlloc'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x13e): undefined reference to `__imp_TVMArrayCopyFromBytes'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0xa45): undefined reference to `__imp_TVMArrayFree'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0xb42): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0xb57): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0xb72): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x1749): undefined reference to `__imp__ZN3tvm7runtime6Module12LoadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x2842): undefined reference to `__imp__ZN3tvm7runtime8Registry3GetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x3304): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
CMakeFiles/test_lib.dir/objects.a(test1.cpp.obj):test1.cpp:(.text+0x3322): undefined reference to `__imp__ZN3tvm7runtime13ExtTypeVTable3GetEi'
collect2: error: ld returned 1 exit status
CMakeFiles/test_lib.dir/build.make:178: recipe for target 'libtest_lib.dll' failed
make[2]: *** [libtest_lib.dll] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_lib.dir/all' failed
make[1]: *** [CMakeFiles/test_lib.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Does anyone have any idea how to solve this issue? When I compile and link normally on linux everything is fine.

P.S. btw I had to maually modify some tvm source code to fix undefined functions that don’t exist in minGW environmet, so I’m wondering if including tvm_runtime_pack.cc in my sources is actually the right way when I wanna cross compile for windows.

You’re not linking against the import library for the tvm runtime.

Thanks for the answer! How can I do so?

@MartynBliss or anyone else willing to share?

When you build the tvm dll, a .lib file should also be generated (with the same name). You need to have this as a dependency for your build.

1 Like