Problem while building test code using C++ frontend with cuda on Win10

tempeslee: <p>Hi, all!<br>
I’m trying to install pytorch c++ frontend with cuda on Win10.<br>
I followed the instruction in <a href="https://towardsdatascience.com/setting-up-a-c-project-in-visual-studio-2019-with-libtorch-1-6-ad8a0e49e82c" rel="noopener nofollow ugc">vs2019 installation guide</a><br>
I read that GPU installation requires torch_cuda.lib, c10_cuda.lib, torch.lib, cudnn64_7.dll, cudart64_102.dll, cublas64_10.dll (for cuda 10.2), but the last three have no .lib files.<br>
So I build lib files from the three dlls using dumpbin.exe &amp; lib.exe.<br>
The final build shows linking errors.</p>
<pre><code class="lang-auto">1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::to(struct c10::TensorOptions const &amp;,bool,bool,class c10::optional&lt;enum c10::MemoryFormat&gt;)const " (__imp_?to@Tensor@at@@QEBA?AV12@AEBUTensorOptions@c10@@_N1V?$optional@W4MemoryFormat@c10@@@4@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::add(class at::Tensor const &amp;,class c10::Scalar)const " (__imp_?add@Tensor@at@@QEBA?AV12@AEBV12@VScalar@c10@@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class at::Tensor __cdecl at::randn(class c10::ArrayRef&lt;__int64&gt;,struct c10::TensorOptions const &amp;)" (__imp_?randn@at@@YA?AVTensor@1@V?$ArrayRef@_J@c10@@AEBUTensorOptions@4@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class at::Tensor __cdecl at::ones(class c10::ArrayRef&lt;__int64&gt;,struct c10::TensorOptions const &amp;)" (__imp_?ones@at@@YA?AVTensor@1@V?$ArrayRef@_J@c10@@AEBUTensorOptions@4@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl c10::TensorImpl::set_autograd_meta(class std::unique_ptr&lt;struct c10::AutogradMetaInterface,struct std::default_delete&lt;struct c10::AutogradMetaInterface&gt; &gt;)" (__imp_?set_autograd_meta@TensorImpl@c10@@QEAAXV?$unique_ptr@UAutogradMetaInterface@c10@@U?$default_delete@UAutogradMetaInterface@c10@@@std@@@std@@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::MessageLogger::~MessageLogger(void)" (__imp_??1MessageLogger@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::MessageLogger::MessageLogger(char const *,int,int)" (__imp_??0MessageLogger@c10@@QEAA@PEBDHH@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "private: void __cdecl c10::ivalue::Object::resizeObject(unsigned __int64)" (?resizeObject@Object@ivalue@c10@@AEAAX_K@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: static struct c10::UndefinedTensorImpl c10::UndefinedTensorImpl::_singleton" (__imp_?_singleton@UndefinedTensorImpl@c10@@0U12@A)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Error::Error(struct c10::SourceLocation,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;)" (__imp_??0Error@c10@@QEAA@USourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl torch::autograd::AutogradMeta::~AutogradMeta(void)" (__imp_??1AutogradMeta@autograd@torch@@UEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl torch::autograd::AutogradMeta::AutogradMeta(struct c10::TensorImpl *,bool,struct torch::autograd::Edge)" (__imp_??0AutogradMeta@autograd@torch@@QEAA@PEAUTensorImpl@c10@@_NUEdge@12@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual class at::Tensor const &amp; __cdecl torch::autograd::AutogradMeta::grad(void)const " (__imp_?grad@AutogradMeta@autograd@torch@@UEBAAEBVTensor@at@@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual class at::Tensor &amp; __cdecl torch::autograd::AutogradMeta::mutable_grad(void)" (__imp_?mutable_grad@AutogradMeta@autograd@torch@@UEAAAEAVTensor@at@@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual bool __cdecl torch::autograd::AutogradMeta::requires_grad(void)const " (__imp_?requires_grad@AutogradMeta@autograd@torch@@UEBA_NXZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual void __cdecl torch::autograd::AutogradMeta::set_requires_grad(bool,struct c10::TensorImpl *)" (__imp_?set_requires_grad@AutogradMeta@autograd@torch@@UEAAX_NPEAUTensorImpl@c10@@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr &amp;&amp;)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@$$QEAU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr const &amp;)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@AEBU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::StrongTypePtr::~StrongTypePtr(void)" (__imp_??1StrongTypePtr@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::StrongTypePtr::StrongTypePtr(struct c10::StrongTypePtr &amp;&amp;)" (__imp_??0StrongTypePtr@c10@@QEAA@$$QEAU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::StrongTypePtr::StrongTypePtr(struct c10::StrongTypePtr const &amp;)" (__imp_??0StrongTypePtr@c10@@QEAA@AEBU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::IValue::IValue(void)" (__imp_??0IValue@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct c10::IValue &amp; __cdecl c10::IValue::operator=(struct c10::IValue const &amp;)&amp; " (__imp_??4IValue@c10@@QEGAAAEAU01@AEBU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct c10::IValue &amp; __cdecl c10::IValue::operator=(struct c10::IValue &amp;&amp;)&amp; " (__imp_??4IValue@c10@@QEGAAAEAU01@$$QEAU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::IValue::~IValue(void)" (__imp_??1IValue@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::IValue::IValue(struct c10::IValue &amp;&amp;)" (__imp_??0IValue@c10@@QEAA@$$QEAU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::IValue::IValue(struct c10::IValue const &amp;)" (__imp_??0IValue@c10@@QEAA@AEBU01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::AutoNonVariableTypeMode::~AutoNonVariableTypeMode(void)" (__imp_??1AutoNonVariableTypeMode@at@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::AutoNonVariableTypeMode::AutoNonVariableTypeMode(bool)" (__imp_??0AutoNonVariableTypeMode@at@@QEAA@_N@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::Tensor::Tensor(class at::Tensor &amp;&amp;)" (__imp_??0Tensor@at@@QEAA@$$QEAV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::Tensor::~Tensor(void)" (__imp_??1Tensor@at@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl at::Tensor::defined(void)const " (__imp_?defined@Tensor@at@@QEBA_NXZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class c10::intrusive_ptr&lt;struct c10::TensorImpl,struct c10::UndefinedTensorImpl&gt; const &amp; __cdecl at::Tensor::getIntrusivePtr(void)const " (__imp_?getIntrusivePtr@Tensor@at@@QEBAAEBV?$intrusive_ptr@UTensorImpl@c10@@UUndefinedTensorImpl@2@@c10@@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::Tensor::Tensor(class c10::intrusive_ptr&lt;struct c10::TensorImpl,struct c10::UndefinedTensorImpl&gt;)" (__imp_??0Tensor@at@@QEAA@V?$intrusive_ptr@UTensorImpl@c10@@UUndefinedTensorImpl@2@@c10@@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl at::Tensor::Tensor(void)" (__imp_??0Tensor@at@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct c10::TensorImpl * __cdecl c10::UndefinedTensorImpl::singleton(void)" (__imp_?singleton@UndefinedTensorImpl@c10@@SAPEAUTensorImpl@2@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::VariableVersion::~VariableVersion(void)" (__imp_??1VariableVersion@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl c10::TensorImpl::set_allow_tensor_metadata_change(bool)" (__imp_?set_allow_tensor_metadata_change@TensorImpl@c10@@QEAAX_N@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl c10::TensorImpl::unique_version(void)const " (__imp_?unique_version@TensorImpl@c10@@QEBA_NXZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::VariableVersion::VariableVersion(unsigned int)" (__imp_??0VariableVersion@c10@@QEAA@I@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_stringstream&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &amp; __cdecl c10::MessageLogger::stream(void)" (__imp_?stream@MessageLogger@c10@@QEAAAEAV?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: void __cdecl c10::TensorOptions::set_device(class c10::optional&lt;struct c10::Device&gt;)&amp; " (__imp_?set_device@TensorOptions@c10@@AEGAAXV?$optional@UDevice@c10@@@2@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl c10::TensorOptions::requires_grad(void)const " (__imp_?requires_grad@TensorOptions@c10@@QEBA_NXZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct c10::TensorOptions __cdecl c10::TensorOptions::requires_grad(class c10::optional&lt;bool&gt;)const " (__imp_?requires_grad@TensorOptions@c10@@QEBA?AU12@V?$optional@_N@2@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::TensorOptions::TensorOptions(void)" (__imp_??0TensorOptions@c10@@QEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: virtual void __cdecl c10::intrusive_ptr_target::release_resources(void)" (__imp_?release_resources@intrusive_ptr_target@c10@@EEAAXXZ)
1&gt;Source.obj : error LNK2001: 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;)" (__imp_??4intrusive_ptr_target@c10@@IEAAAEAV01@AEBV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: __cdecl c10::intrusive_ptr_target::intrusive_ptr_target(class c10::intrusive_ptr_target const &amp;)" (__imp_??0intrusive_ptr_target@c10@@IEAA@AEBV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: class c10::intrusive_ptr_target &amp; __cdecl c10::intrusive_ptr_target::operator=(class c10::intrusive_ptr_target &amp;&amp;)" (__imp_??4intrusive_ptr_target@c10@@IEAAAEAV01@$$QEAV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: __cdecl c10::intrusive_ptr_target::intrusive_ptr_target(class c10::intrusive_ptr_target &amp;&amp;)" (__imp_??0intrusive_ptr_target@c10@@IEAA@$$QEAV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: __cdecl c10::intrusive_ptr_target::intrusive_ptr_target(void)" (__imp_??0intrusive_ptr_target@c10@@IEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual __cdecl c10::intrusive_ptr_target::~intrusive_ptr_target(void)" (__imp_??1intrusive_ptr_target@c10@@MEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Scalar::Scalar(int)" (__imp_??0Scalar@c10@@QEAA@H@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Error::Error(class c10::Error const &amp;)" (__imp_??0Error@c10@@QEAA@AEBV01@@Z)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl c10::Error::~Error(void)" (__imp_??1Error@c10@@UEAA@XZ)
1&gt;Source.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Device::Device(enum c10::DeviceType,short)" (__imp_??0Device@c10@@QEAA@W4DeviceType@1@F@Z)
1&gt;D:\OneDrive\Work\Development\TorchTest\x64\Release\TorchTest.exe : fatal error LNK1120: 56 unresolved externals
</code></pre>
<p>My environment is<br>
Win10<br>
Visual Studio 2019 Community (x64 Release)<br>
Pytorch 1.7<br>
CUDA 10.2</p>
<p>Thanks <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=9" title=":grinning:" class="emoji" alt=":grinning:"></p>