Unresolved external symbol (LNK2019) for c10 in Windows

username: KRG
cooked: <p>I tried to build a Visual Studio sample project using LibTorch but got LNK2019 unresolved external associated with the c10 library.</p>
<pre><code class="lang-auto">Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::WeakOrStrongTypePtr::WeakOrStrongTypePtr(struct c10::WeakTypePtr)" (__imp_??0WeakOrStrongTypePtr@c10@@QEAA@UWeakTypePtr@1@@Z) referenced in function "public: void __cdecl c10::ivalue::Object::unsafe_make_weak_compilation_ref(void)" (?unsafe_make_weak_compilation_ref@Object@ivalue@c10@@QEAAXXZ)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK1120	14 unresolved externals	TorchProject	C:\Users\user\test_project\TorchProject\x64\Release\TorchProject.exe	1	
Error	LNK2001	unresolved external symbol "class at::Tensor __cdecl at::native::_torch_cuda_cu_linker_symbol_op_cuda(class at::Tensor const &amp;)" (?_torch_cuda_cu_linker_symbol_op_cuda@native@at@@YA?AVTensor@2@AEBV32@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\LINK	1	
Error	LNK2001	unresolved external symbol "public: __cdecl c10::WeakOrStrongTypePtr::~WeakOrStrongTypePtr(void)" (??1WeakOrStrongTypePtr@c10@@QEAA@XZ)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: bool __cdecl c10::WeakOrStrongTypePtr::holds_strong_ref(void)const " (__imp_?holds_strong_ref@WeakOrStrongTypePtr@c10@@QEBA_NXZ) referenced in function "public: class std::shared_ptr&lt;struct torch::jit::CompilationUnit&gt; __cdecl c10::ivalue::Object::compilation_unit(void)" (?compilation_unit@Object@ivalue@c10@@QEAA?AV?$shared_ptr@UCompilationUnit@jit@torch@@@std@@XZ)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr&lt;struct c10::TensorType&gt; const &amp; __cdecl c10::TensorType::get(void)" (__imp_?get@TensorType@c10@@SAAEBV?$shared_ptr@UTensorType@c10@@@std@@XZ) referenced in function "public: __cdecl c10::IValue::IValue&lt;class at::Tensor,0&gt;(class std::vector&lt;class at::Tensor,class std::allocator&lt;class at::Tensor&gt; &gt; const &amp;)" (??$?0VTensor@at@@$0A@@IValue@c10@@QEAA@AEBV?$vector@VTensor@at@@V?$allocator@VTensor@at@@@std@@@std@@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::IValue const &amp; __cdecl c10::ivalue::TupleElements::at(unsigned __int64)const " (__imp_?at@TupleElements@ivalue@c10@@QEBAAEBUIValue@3@_K@Z) referenced in function "void __cdecl draw_images(struct c10::IValue,class cv::Mat,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;)" (?draw_images@@YAXUIValue@c10@@VMat@cv@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::WeakOrStrongTypePtr &amp; __cdecl c10::WeakOrStrongTypePtr::operator=(struct c10::WeakOrStrongTypePtr &amp;&amp;)" (__imp_??4WeakOrStrongTypePtr@c10@@QEAAAEAU01@$$QEAU01@@Z) referenced in function "public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object &amp;&amp;)" (??4Object@ivalue@c10@@QEAAAEAU012@$$QEAU012@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::WeakOrStrongTypePtr &amp; __cdecl c10::WeakOrStrongTypePtr::operator=(struct c10::WeakOrStrongTypePtr const &amp;)" (__imp_??4WeakOrStrongTypePtr@c10@@QEAAAEAU01@AEBU01@@Z) referenced in function "public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &amp;)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::WeakTypePtr __cdecl c10::WeakOrStrongTypePtr::asWeakTypePtr(void)const " (__imp_?asWeakTypePtr@WeakOrStrongTypePtr@c10@@QEBA?AUWeakTypePtr@2@XZ) referenced in function "public: void __cdecl c10::ivalue::Object::unsafe_make_weak_compilation_ref(void)" (?unsafe_make_weak_compilation_ref@Object@ivalue@c10@@QEAAXXZ)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::IValue::IValue(class at::TensorBase)" (__imp_??0IValue@c10@@QEAA@VTensorBase@at@@@Z) referenced in function "public: __cdecl c10::IValue::IValue&lt;class at::Tensor,0&gt;(class std::vector&lt;class at::Tensor,class std::allocator&lt;class at::Tensor&gt; &gt; const &amp;)" (??$?0VTensor@at@@$0A@@IValue@c10@@QEAA@AEBV?$vector@VTensor@at@@V?$allocator@VTensor@at@@@std@@@std@@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::WeakOrStrongTypePtr::WeakOrStrongTypePtr(struct c10::StrongTypePtr)" (__imp_??0WeakOrStrongTypePtr@c10@@QEAA@UStrongTypePtr@1@@Z) referenced in function "public: __cdecl c10::ivalue::Object::Object(struct c10::StrongTypePtr,unsigned __int64)" (??0Object@ivalue@c10@@QEAA@UStrongTypePtr@2@_K@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::WeakOrStrongTypePtr::WeakOrStrongTypePtr(struct c10::WeakOrStrongTypePtr &amp;&amp;)" (__imp_??0WeakOrStrongTypePtr@c10@@QEAA@$$QEAU01@@Z) referenced in function "public: __cdecl c10::ivalue::Object::Object(struct c10::ivalue::Object &amp;&amp;)" (??0Object@ivalue@c10@@QEAA@$$QEAU012@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::WeakOrStrongTypePtr::WeakOrStrongTypePtr(struct c10::WeakOrStrongTypePtr const &amp;)" (__imp_??0WeakOrStrongTypePtr@c10@@QEAA@AEBU01@@Z) referenced in function "public: __cdecl c10::ivalue::Object::Object(struct c10::ivalue::Object const &amp;)" (??0Object@ivalue@c10@@QEAA@AEBU012@@Z)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::WeakOrStrongTypePtr::~WeakOrStrongTypePtr(void)" (__imp_??1WeakOrStrongTypePtr@c10@@QEAA@XZ) referenced in function "int `public: __cdecl c10::ivalue::Object::Object(struct ivalue::Object::dtor$1 const &amp;)'::`1'::dtor$1" (?dtor$1@?0???0Object@ivalue@c10@@QEAA@AEBU012@@Z@4HA)	TorchProject	C:\Users\user\test_project\TorchProject\example-app.obj	1	
</code></pre>
<p>Libtorch - libtorch-win-shared-with-deps-1.12.1+cu113<br>
Cuda - 11.3</p>
<p>include directories</p>
<pre><code class="lang-auto">C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include
C:\Program Files\NVIDIA Corporation\NvToolsExt\include
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\include
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\include\torch\csrc\api\include
C:\Program Files (x86)\torchvision\include
C:\OpenCV\include
</code></pre>
<p>Additional library</p>
<pre><code class="lang-auto">C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\lib\x64
C:\Program Files\NVIDIA Corporation\NvToolsExt\lib\x64
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\asmjit.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\c10.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\c10_cuda.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\caffe2_nvrtc.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\cpuinfo.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\fbgemm.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\kineto.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\libprotobuf.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\libprotobuf-lite.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\libprotoc.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\pthreadpool.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\torch.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\torch_cpu.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\torch_cuda.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\torch_cuda_cpp.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\torch_cuda_cu.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib\XNNPACK.lib
C:\libtorch-win-shared-with-deps-1.12.1+cu113\libtorch\lib
C:\Program Files (x86)\torchvision\lib
C:\OpenCV\x64\vc16\lib
</code></pre>
<p>I have linked all the libraries as shown above in Visual Studio. What can be the issue here?</p>

username: KRG
cooked: <ul>
<li>
<p>If you are using visual-studio-extension (<a href="https://pytorch.org/cppdocs/installing.html#visual-studio-extension" class="inline-onebox" rel="noopener nofollow ugc">Installing C++ Distributions of PyTorch — PyTorch master documentation</a>) for the project, all the required libraries (LibTorch, CUDA, vision etc.) need to be added to Properties → Linker → Input → Additional Dependencies. Adding the lib folder to ‘Properties → Linker → Additional Library Directories’ didn’t work for me.</p>
</li>
<li>
<p>The version worked for me - CUDA- 11.6 , LibTorch - libtorch-win-shared-with-deps-1.13.0+cu116.</p>
</li>
</ul>