I built static libtorch from sources on windows successfully.
But now when I compile my application, I must explicitly link with onnx, onnx_proto, caffe2_ptoros, mkldnn, mkl, protobuf libraries (my compile options). This is not convenient, but it works. But for fbgemm library this doesn’t work. I get link errors:
torch_cpu.lib(Context.cpp.obj) : 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_8dd2a8e98f77cf43df1066af8f7a0e
c7>::operator()(void)const " (??R<lambda_8dd2a8e98f77cf43df1066af8f7a0ec7>@@QEBA?AV?$vector@W4QEngine@c10@@V?$allocator@W4QEngine@c10@@@std@@@std@@XZ) [D:\reps\libtorch_tes
t\deploy\example-app.vcxproj]
torch_cpu.lib(Quantizer.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::fbgemmPartition1D(int,int,int,int &,int &)" (__imp_
?fbgemmPartition1D@fbgemm@@YAXHHHAEAH0@Z) referenced in function "void __cdecl fbgemm::Dequantize<signed char>(signed char const *,float *,int,struct fbgemm::TensorQuantiza
tionParams const &,int,int)" (??$Dequantize@C@fbgemm@@YAXPEBCPEAMHAEBUTensorQuantizationParams@0@HH@Z) [D:\reps\libtorch_test\deploy\example-app.vcxproj]
torch_cpu.lib(Quantizer.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::Quantize<signed char>(float const *,signed char *,i
nt,struct fbgemm::TensorQuantizationParams const &,int,int)" (__imp_??$Quantize@C@fbgemm@@YAXPEBMPEACHAEBUTensorQuantizationParams@0@HH@Z) referenced in function "void __cd
ecl at::parallel_for$omp$1<class <lambda_11019aac2f2763b0156a5bd7dbaca06d> >(__int64,__int64,__int64,class <lambda_11019aac2f2763b0156a5bd7dbaca06d> const &)" (??$parallel_
for$omp$1@V<lambda_11019aac2f2763b0156a5bd7dbaca06d>@@@at@@YAX_J00AEBV<lambda_11019aac2f2763b0156a5bd7dbaca06d>@@@Z) [D:\reps\libtorch_test\deploy\example-app.vcxproj]
torch_cpu.lib(Quantizer.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::Quantize<unsigned char>(float const *,unsigned char
*,int,struct fbgemm::TensorQuantizationParams const &,int,int)" (__imp_??$Quantize@E@fbgemm@@YAXPEBMPEAEHAEBUTensorQuantizationParams@0@HH@Z) referenced in function "void
__cdecl at::parallel_for$omp$1<class <lambda_7b353a87181e064310fa419329247f98> >(__int64,__int64,__int64,class <lambda_7b353a87181e064310fa419329247f98> const &)" (??$paral
lel_for$omp$1@V<lambda_7b353a87181e064310fa419329247f98>@@@at@@YAX_J00AEBV<lambda_7b353a87181e064310fa419329247f98>@@@Z) [D:\reps\libtorch_test\deploy\example-app.vcxproj]
torch_cpu.lib(Quantizer.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::Quantize<int>(float const *,int *,int,struct fbgemm
::TensorQuantizationParams const &,int,int)" (__imp_??$Quantize@H@fbgemm@@YAXPEBMPEAHHAEBUTensorQuantizationParams@0@HH@Z) referenced in function "void __cdecl at::parallel
_for$omp$1<class <lambda_ac0c20011d29a38651cff09b26e44b16> >(__int64,__int64,__int64,class <lambda_ac0c20011d29a38651cff09b26e44b16> const &)" (??$parallel_for$omp$1@V<lamb
da_ac0c20011d29a38651cff09b26e44b16>@@@at@@YAX_J00AEBV<lambda_ac0c20011d29a38651cff09b26e44b16>@@@Z) [D:\reps\libtorch_test\deploy\example-app.vcxproj]
torch_cpu.lib(THBlas.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::cblas_gemm_i64_i64acc(enum fbgemm::matrix_op_t,enum fb
gemm::matrix_op_t,int,int,int,__int64 const *,int,__int64 const *,int,bool,__int64 *,int)" (__imp_?cblas_gemm_i64_i64acc@fbgemm@@YAXW4matrix_op_t@1@0HHHPEB_JH1H_NPEA_JH@Z)
referenced in function THLongBlas_gemm [D:\reps\libtorch_test\deploy\example-app.vcxproj]
D:\reps\libtorch_test\deploy\Release\example-app.exe : fatal error LNK1120: 6 unresolved externals [D:\reps\libtorch_test\deploy\example-app.vcxproj]
This means that the libtorch wants to link to the fbgemm as dynamic library. But fbgemm built as static library without __declspec(dllexport) .