Libtorch static library

Hello I am building libtorch has static library. But now I am struggling to have a binary code running properly.

So I try few stuff:

  1. Just linking my main.cpp with all the static library from libtorch
    –> Result : abort libc++aby.dylib: terminating with uncaught exception of type c10::bad_optionnal_access

  2. I was suspecting it could be because I need to use whole_archive, I put all the library with whole_archive but few issue:
    –> undefined reference of onnxifi_loader
    2.1) I copy the missing libonnxifi_loader.a
    –> exec format error: my_torch_sample

I am not sure what should I do next, any suggestion how to use Libtorch as a static library ?

Thanks

3 Likes

After fighting few hours, I finally figure out the trouble with the static library of pytorch.
The main trouble was the --force-load or --whole-archive need to be apply on some specific library not only torch but not all of them.

Now I am able to run libtorch with and without Cuda over:
OSX Catalina (CPU)
OSX High Sierra (CPU/GPU)
Ubuntu 18.04 (CPU/GPU)

I am facing another issue now on Windows. The build failed because of this error :
error C2338: CopyToCPU requires fundamental types
If someone has an idea how to fix it, that will be very nice.

Thanks

After looking to the pytorch issues it seems there is a patch for this one but not inside the latest release.

I apply it and its now build fine but still failed to link because of size:

Fatal error LNK1248: image size exceeds maximum allowable

I am building with ninja in release, I am not sure how I can fix this one, any suggestion.

Thanks

Would you please try whether set MSVC_Z7_OVERRIDE=OFF works?

Hi @peterjc123,

I try to set MSVC_Z7 but still have the same issue, finally I am building torch using MinSizeRel and it seems to be working fine, I was able to build a cpu version of torch for windows 10.

Currently building the GPU version.

Thanks

I was finally able to build my static windows version of torch using cuda.
Unfortunately now I have another issue.

If I link the library normally I can run my sample but I received an exception from CUDA when I try to use it. It make sense because I need to use the link flag WHOLE_ARCHIVE.

But if I use it with my static library torch. When I try to launch my executable I have a direct segfault.

Someone has an idea why torch will give me a segfault like that, I will try to have mode info why is giving a segfault but if someone have an idea it will be really useful.

Thanks

I am also facing same issue, could you please share how you are loading libraries (with options)?

Would you like to share how to build Libtorch static libraries?
As Static linking master bug #21737 indicates, not a few user are interested in this issue.

Hi Guys, sorry to take so long before giving a response, I was off for few weeks, but here I am back.

So I am currently building CPU and GPU version of Torch as static library.

First of all the first time I try I was using lib torch 1.3.1 and 1.4 but same if I was able to build successfully my perf was extremely bad so I decide to move to a more recent version:

So I am currently using this checkout 246b208e4f60d6894ffaeeed8c9746e331fa6f6f : I am almost sure a most recent version should work too.

In order to build I try both calling CMake directly and using Python script and both work for me:

-DBUILD_CAFFE2_MOBILE=OFF;
-DBUILD_SHARED_LIBS=OFF;
-DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON;
-DMSVC_Z7_OVERRIDE=OFF;
-DUSE_CUDA=OFF/ON;
-DBUILD_PYTHON=OFF;
-DBUILD_TEST=OFF;

One important point I decide to use Visual Studio 2019 too build, when using the script python I decide to force two part:

  1. Disable python : HERE
  2. Force Visual studio 2019: HERE

I am sure there are better way to bypass those value, but for me it was enough like that.

After that the build was going smooth and I add all the static library ready then for linking here what I use:
For CPU only:

        WHOLE_LIBRARIES
        torch;
        torch_cpu;

        LIBRARIES
        clog
        cpuinfo;
        libprotobuf;
        libprotoc;
        onnx_proto;
        onnx;
        c10;
        fbgemm;
        dnnl;
        foxi_loader;
        caffe2_protos;
        Caffe2_perfkernels_avx;
        Caffe2_perfkernels_avx2;
        Caffe2_perfkernels_avx512;

For GPU:

        WHOLE_LIBRARIES
        torch_cpu;
        torch_cuda;
        c10_cuda;

        LIBRARIES
        asmjit
        c10
        c10_cuda
        Caffe2_perfkernels_avx
        Caffe2_perfkernels_avx2
        Caffe2_perfkernels_avx512
        caffe2_protos
        clog
        cpuinfo_internals
        cpuinfo
        dnnl
        fbgemm
        foxi_loader
        mkldnn
        onnx_proto
        onnx
        libprotobuf
        libprotoc
        torch

LIBRARIES

TARGET_LINK_LIBRARIES(${__NAME}${_SUFFIX} INTERFACE ${LIBNAME})

WHOLE_LIBRARIES

TARGET_LINK_LIBRARIES(${__NAME}${_SUFFIX} INTERFACE -WHOLEARCHIVE:${LIBNAME})

3 Likes

I appreciate your kindness.
I will try your build options.
Thanks!

I have write a blog for pytorch static build: https://zhuanlan.zhihu.com/p/313481517.
For non-Chinese reader, I believe google translator will be helpful.

1 Like

Hi, Thanks, I followed your explanation and tried to build it on windows but I faced these errors :

C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(6,1): error C2653: 'PThreadPool': is not a class
 or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,5): error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,19): error C3861: 'pthreadpool_create': identi
fier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,53): error C2065: 'pthreadpool_destroy': undec
lared identifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,74): error C2550: 'caffe2::PThreadPool': const
ructor initializer lists are only allowed on constructor definitions [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.
vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(9,8): error C2653: 'PThreadPool': is not a class
 or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(9,46): error C2270: 'get_thread_count': modifier
s not allowed on nonmember functions [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(12,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(13,40): error C2065: 'threadpool_': undeclared i
dentifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(13,10): error C3861: 'pthreadpool_get_threads_co
unt': identifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(16,6): error C2653: 'PThreadPool': is not a clas
s or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(25,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(25,21): error C3861: 'pthreadpool_create': ident
ifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(28,6): error C2653: 'PThreadPool': is not a clas
s or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,16): error C2039: 'function': is not a member
 of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,24): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,24): error C2143: syntax error: missing ',' b
efore '<' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(33,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
  generated_unboxing_wrappers_2.cpp
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,16): error C2039: 'function': is not a member
 of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,24): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,24): error C2143: syntax error: missing ';' b
efore '<' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,42): error C2238: unexpected token(s) precedi
ng ';' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(38,7): error C2065: 'fn': undeclared identifier
[C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(42,7): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(48,46): error C2039: 'fn': is not a member of 'c
affe2::run::Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(35): message : see declaration of 'caffe2::run::
Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(48,1): error C2039: '__this': is not a member of
 'caffe2::run::Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(35): message : see declaration of 'caffe2::run::
Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(51,7): error C2065: 'range': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(41,3): error C3861: 'pthreadpool_parallelize_1d'
: identifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,12): error C2143: syntax error: missing ';' b
efore '*' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,12): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,1): error C2365: 'caffe2::PThreadPool': redef
inition; previous definition was 'function' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(6): message : see declaration of 'caffe2::PThrea
dPool' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2059: syntax error: '{' [C:\Users
\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2143: syntax error: missing ';' b
efore '{' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2447: '{': missing function heade
r (old-style formal list?) [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,27): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,15): error C2146: syntax error: missing ';' b
efore identifier 'pthreadpool_' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,30): error C2143: syntax error: missing ';' b
efore '{' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,30): error C2447: '{': missing function heade
r (old-style formal list?) [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
  VariableType_0.cpp

Update1 :

OK I manually excluded the pthreadpool-cpp.cc from torch_cpu project and everything seemingly build successfully and I have bunch of lib files.
However upon linking I’m getting these errors :

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol sswap_ referenced in function "void __cdecl THFloatBlas_swap(__int64,float *,__int64,float *,__int64)" (?THFloatBlas_swap@@YAX_JPEAM010@Z)	Detector_MTCNN_Test	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector_Test\torch_cpu.lib(THBlas.obj)	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl c10::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct c10::Half const &)" (__imp_??6c10@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV12@AEBUHalf@0@@Z) referenced in function "public: void __cdecl <lambda_4b127653adfae3530aa9273c394680d7>::operator()(void)const " (??R<lambda_4b127653adfae3530aa9273c394680d7>@@QEBAXXZ)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Scalar::Scalar(void)" (__imp_??0Scalar@c10@@QEAA@XZ) referenced in function "public: __cdecl torch::detail::TensorDataContainer::TensorDataContainer(class c10::ArrayRef<__int64>)" (??0TensorDataContainer@detail@torch@@QEAA@V?$ArrayRef@_J@c10@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) protected: __cdecl c10::intrusive_ptr_target::intrusive_ptr_target(class c10::intrusive_ptr_target const &)" (__imp_??0intrusive_ptr_target@c10@@IEAA@AEBV01@@Z) referenced in function "public: __cdecl c10::ivalue::Object::Object(struct c10::ivalue::Object const &)" (??0Object@ivalue@c10@@QEAA@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) protected: class c10::intrusive_ptr_target & __cdecl c10::intrusive_ptr_target::operator=(class c10::intrusive_ptr_target const &)" (__imp_??4intrusive_ptr_target@c10@@IEAAAEAV01@AEBV01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::TensorOptions::TensorOptions(class caffe2::TypeMeta)" (__imp_??0TensorOptions@c10@@QEAA@VTypeMeta@caffe2@@@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::GetAffineTransformMatrix(class at::Tensor,class at::Tensor)" (?GetAffineTransformMatrix@DetectorImpl@@QEAA?AVTensor@at@@V23@0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor & __cdecl at::Tensor::operator*=(class c10::Scalar)" (__imp_??XTensor@at@@QEAAAEAV01@VScalar@c10@@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::operator[](class at::Tensor)const " (__imp_??ATensor@at@@QEBA?AV01@V01@@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::NMS(class at::Tensor,float,enum NMSMode)" (?NMS@DetectorImpl@@QEAA?AVTensor@at@@V23@MW4NMSMode@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::index(class std::initializer_list<struct at::indexing::TensorIndex>)const " (__imp_?index@Tensor@at@@QEBA?AV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor & __cdecl at::Tensor::index_put_(class std::initializer_list<struct at::indexing::TensorIndex>,class at::Tensor const &)" (__imp_?index_put_@Tensor@at@@QEAAAEAV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@AEBV12@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor & __cdecl at::Tensor::index_put_(class std::initializer_list<struct at::indexing::TensorIndex>,class c10::Scalar)" (__imp_?index_put_@Tensor@at@@QEAAAEAV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@VScalar@c10@@@Z) referenced in function "public: class std::array<class at::Tensor,10> __cdecl DetectorImpl::CorrectBBoxes(class at::Tensor,float,float)" (?CorrectBBoxes@DetectorImpl@@QEAA?AV?$array@VTensor@at@@$09@std@@VTensor@at@@MM@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::Slice::Slice(class c10::optional<__int64>,class c10::optional<__int64>,class c10::optional<__int64>)" (__imp_??0Slice@indexing@at@@QEAA@V?$optional@_J@c10@@00@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(__int64)" (__imp_??0TensorIndex@indexing@at@@QEAA@_J@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::NMS(class at::Tensor,float,enum NMSMode)" (?NMS@DetectorImpl@@QEAA?AVTensor@at@@V23@MW4NMSMode@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(int)" (__imp_??0TensorIndex@indexing@at@@QEAA@H@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(struct at::indexing::Slice)" (__imp_??0TensorIndex@indexing@at@@QEAA@USlice@12@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(class at::Tensor)" (__imp_??0TensorIndex@indexing@at@@QEAA@VTensor@2@@Z) referenced in function "public: class std::array<class at::Tensor,10> __cdecl DetectorImpl::CorrectBBoxes(class at::Tensor,float,float)" (?CorrectBBoxes@DetectorImpl@@QEAA?AV?$array@VTensor@at@@$09@std@@VTensor@at@@MM@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::~TensorIndex(void)" (__imp_??1TensorIndex@indexing@at@@QEAA@XZ) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr & __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr const &)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@AEBU01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr & __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr &&)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@$$QEAU01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object &&)" (??4Object@ivalue@c10@@QEAAAEAU012@$$QEAU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::IValue __cdecl torch::jit::Module::forward(class std::vector<struct c10::IValue,class std::allocator<struct c10::IValue> >)" (__imp_?forward@Module@jit@torch@@QEAA?AUIValue@c10@@V?$vector@UIValue@c10@@V?$allocator@UIValue@c10@@@std@@@std@@@Z) referenced in function "public: struct std::pair<class at::Tensor,class at::Tensor> __cdecl DetectorImpl::DetectFaces(class cv::Mat &,float,class std::array<float,3>,class std::array<float,3>)" (?DetectFaces@DetectorImpl@@QEAA?AU?$pair@VTensor@at@@V12@@std@@AEAVMat@cv@@MV?$array@M$02@3@1@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: void __cdecl torch::jit::Module::eval(void)" (__imp_?eval@Module@jit@torch@@QEAAXXZ) referenced in function "public: struct std::pair<class at::Tensor,class at::Tensor> __cdecl DetectorImpl::DetectFaces(class cv::Mat &,float,class std::array<float,3>,class std::array<float,3>)" (?DetectFaces@DetectorImpl@@QEAA?AU?$pair@VTensor@at@@V12@@std@@AEAVMat@cv@@MV?$array@M$02@3@1@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) bool __cdecl fbgemm::fbgemmSupportedCPU(void)" (__imp_?fbgemmSupportedCPU@fbgemm@@YA_NXZ) referenced in function "public: class std::vector<enum c10::QEngine,class std::allocator<enum c10::QEngine> > __cdecl <lambda_fcc5437ea6fb470d27a4c81929ec1286>::operator()(void)const " (??R<lambda_fcc5437ea6fb470d27a4c81929ec1286>@@QEBA?AV?$vector@W4QEngine@c10@@V?$allocator@W4QEngine@c10@@@std@@@std@@XZ)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\torch_cpu.lib(Context.cpp.obj)	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::Quantize<signed char,0>(float const *,signed char *,int,struct fbgemm::TensorQuantizationParams const &,int,int)" (__imp_??$Quantize@C$0A@@fbgemm@@YAXPEBMPEACHAEBUTensorQuantizationParams@0@HH@Z) referenced in function "void __cdecl at::native::quantize_vec<struct c10::qint8,8>(double,__int64,float const *,struct c10::qint8 *,unsigned __int64)" (??$quantize_vec@Uqint8@c10@@$07@native@at@@YAXN_JPEBMPEAUqint8@c10@@_K@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\torch_cpu.lib(affine_quantizer.obj)	1	

Heres the full linker errors : https://paste.ee/p/AFZ1l
and this is the VS output : https://paste.ee/p/uF8Jz
which shows linker warnings such as :

1>   Creating library D:\Codes\fac_ver\cpp\port\LibtorchPort\x64\Debug\Test_dummy.lib and object D:\Codes\fac_ver\cpp\port\LibtorchPort\x64\Debug\Test_dummy.exp
1>LINK : warning LNK4217: symbol '??0Error@c10@@QEAA@USourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z (public: __cdecl c10::Error::Error(struct c10::SourceLocation,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >))' defined in 'c10.lib(Logging.obj)' is imported by 'Test_dummy.obj' in function '"public: __cdecl torch::detail::TensorDataContainer::TensorDataContainer(class std::initializer_list<struct torch::detail::TensorDataContainer>)" (??0TensorDataContainer@detail@torch@@QEAA@V?$initializer_list@UTensorDataContainer@detail@torch@@@std@@@Z)'
1>LINK : warning LNK4217: symbol '?msg@Error@c10@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ (public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl c10::Error::msg(void)const )' defined in 'c10.lib(Logging.obj)' is imported by 'Test_dummy.obj' in function '__catch$?ToTensor@@YA?AVTensor@at@@AEBVMat@cv@@AEB_N1AEBH@Z$0'

What should I do?

I’m building 1.7.0 as well (cpu only)
I’d greatly appreciate any kind of help in this.

Are there any updates for this issue?