Error while linking libs to project statically

username: dawachat
cooked: <p>I have build the libs of pytorch statically for windows when I link to my project I get the follow error.</p>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2019	unresolved external symbol “__declspec(dllimport) public: __cdecl c10::ivalue::Future::FutureError::FutureError(struct c10::ivalue::Future::FutureError &amp;&amp;)” (_<em>imp</em>??0FutureError@Future@ivalue@c10@<span class="mention">@QEAA</span>@$$QEAU0123@<span class="mention">@Z</span>) referenced in function “public: class c10::optional &amp; __cdecl c10::optional::operator=(struct c10::ivalue::Future::FutureError &amp;&amp;)” (??$?4UFutureError@Future@ivalue@c10@@@?$optional@UFutureError@Future@ivalue@c10@@<span class="mention">@c10</span>@<span class="mention">@QEAAAEAV01</span>@$$QEAUFutureError@Future@ivalue@1@<span class="mention">@Z</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2019	unresolved external symbol “__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr const &amp;)” (_<em>imp</em>??4StrongTypePtr@c10@<span class="mention">@QEAAAEAU01</span>@AEBU01@<span class="mention">@Z</span>) referenced in function “public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &amp;)” (??4Object@ivalue@c10@<span class="mention">@QEAAAEAU012</span>@AEBU012@<span class="mention">@Z</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2019	unresolved external symbol “__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr &amp;&amp;)” (_<em>imp</em>??4StrongTypePtr@c10@<span class="mention">@QEAAAEAU01</span>@$$QEAU01@<span class="mention">@Z</span>) referenced in function “public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object &amp;&amp;)” (??4Object@ivalue@c10@<span class="mention">@QEAAAEAU012</span>@$$QEAU012@<span class="mention">@Z</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2019	unresolved external symbol “__declspec(dllimport) public: struct c10::ivalue::Future::FutureError &amp; __cdecl c10::ivalue::Future::FutureError::operator=(struct c10::ivalue::Future::FutureError &amp;&amp;)” (_<em>imp</em>??4FutureError@Future@ivalue@c10@<span class="mention">@QEAAAEAU0123</span>@$$QEAU0123@<span class="mention">@Z</span>) referenced in function “public: class c10::optional &amp; __cdecl c10::optional::operator=(struct c10::ivalue::Future::FutureError &amp;&amp;)” (??$?4UFutureError@Future@ivalue@c10@@@?$optional@UFutureError@Future@ivalue@c10@@<span class="mention">@c10</span>@<span class="mention">@QEAAAEAV01</span>@$$QEAUFutureError@Future@ivalue@1@<span class="mention">@Z</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2019	unresolved external symbol “__declspec(dllimport) protected: class c10::intrusive_ptr_target &amp; __cdecl c10::intrusive_ptr_target::operator=(class c10::intrusive_ptr_target const &amp;)” (_<em>imp</em>??4intrusive_ptr_target@c10@<span class="mention">@IEAAAEAV01</span>@AEBV01@<span class="mention">@Z</span>) referenced in function “public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &amp;)” (??4Object@ivalue@c10@<span class="mention">@QEAAAEAU012</span>@AEBU012@<span class="mention">@Z</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<blockquote>
<p>Severity	Code	Description	Project	File	Line	Suppression State<br>
Error	LNK2001	unresolved external symbol “public: virtual class at::Tensor &amp; __cdecl torch::autograd::AutogradMeta::grad(void)” (?grad@AutogradMeta@autograd@torch@<span class="mention">@UEAAAEAVTensor</span>@at@<span class="mention">@XZ</span>)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1</p>
</blockquote>
<p>Following is my cmake code</p>
<blockquote>
<p>cmake_minimum_required(VERSION 3.0 FATAL_ERROR)<br>
project(example-app-debug)<br>
add_executable(example-app-debug example-app-debug.cpp)<br>
set(TORCH_INCLUDE_DIRS “C:/Users/dawachat/Desktop/example-app-debug/libtorch/include/” “C:/Users/dawachat/Desktop/example-app-debug/libtorch/include/torch/csrc/api/include”)<br>
include_directories(${TORCH_INCLUDE_DIRS})<br>
set(torch_lib “${tp}/asmjit.lib”)<br>
<span class="hashtag-raw">#set</span>(torch_lib “${tp}/clog.lib”)<br>
list(APPEND torch_lib “${tp}/clog.lib”)<br>
list(APPEND torch_lib “${tp}/cpuinfo.lib”)<br>
list(APPEND torch_lib “${tp}/cpuinfo_internals.lib”)<br>
list(APPEND torch_lib “${tp}/libprotobuf.lib”)<br>
list(APPEND torch_lib “${tp}/libprotobuf-lite.lib”)<br>
list(APPEND torch_lib “${tp}/libprotoc.lib”)<br>
list(APPEND torch_lib “${tp}/onnx_proto.lib”)<br>
list(APPEND torch_lib “${tp}/onnx.lib”)<br>
list(APPEND torch_lib “${tp}/c10.lib”)<br>
list(APPEND torch_lib “${tp}/fbgemm.lib”)<br>
<span class="hashtag-raw">#list</span>(APPEND torch_lib “${tp}/dnnl.lib”)<br>
<span class="hashtag-raw">#list</span>(APPEND torch_lib “${tp}/mkldnn.lib”)<br>
list(APPEND torch_lib “${tp}/fmt.lib”)<br>
list(APPEND torch_lib “${tp}/foxi_loader.lib”)<br>
list(APPEND torch_lib “${tp}/caffe2_protos.lib”)<br>
list(APPEND torch_lib “${tp}/Caffe2_perfkernels_avx.lib”)<br>
list(APPEND torch_lib “${tp}/Caffe2_perfkernels_avx2.lib”)<br>
list(APPEND torch_lib “${tp}/Caffe2_perfkernels_avx512.lib”)<br>
set(torch_whole “${tp}/torch_cpu.lib”)<br>
message ( STATUS “libraries: ${torch_lib}” )<br>
message ( STATUS “libraries: ${torch_whole}” )<br>
target_link_libraries(example-app-debug PUBLIC ${torch_lib})<br>
target_link_libraries(example-app-debug PUBLIC -WHOLEARCHIVE:“${tp}/torch.lib”)<br>
target_link_libraries(example-app-debug PUBLIC -WHOLEARCHIVE:“${torch_whole}”)</p>
</blockquote>