0

I have written a program which needs to use libtorch libs. I use libtorch-win-shared-with-deps-1.5.0 package,I have configured my project to make linker->input include c10.lib as shown below enter image description here

enter image description here

When I compile this project I received three link error:

 LNK2019    无法解析的外部符号 "__declspec(dllimport) public: class
 c10::basic_string_view<char> __cdecl caffe2::TypeMeta::name(void)const
 " (__imp_?name@TypeMeta@caffe2@@QEBA?AV?$basic_string_view@D@c10@@XZ)  
 
 LNK2019    无法解析的外部符号 "__declspec(dllimport) public: class
 c10::DispatchKeySet __cdecl c10::TensorOptions::key_set(void)const "
 (__imp_?key_set@TensorOptions@c10@@QEBA?AVDispatchKeySet@2@XZ)
 
 LNK2019    无法解析的外部符号 "__declspec(dllimport) public: void __cdecl
 c10::TensorImpl::set_allow_tensor_metadata_change(bool)"
 (__imp_?set_allow_tensor_metadata_change@TensorImpl@c10@@QEAAX_N@Z)

it looks like I did not specify the right *.lib, but when I inspect the c10.lib which I specified, I get this:

enter image description
here

It looks like my configuration is right and I have specified the right c10.lib, but why I get this link error?

geoff3jones
  • 605
  • 1
  • 7
  • 17
luffy
  • 1
  • Two possible problems i can think of: It is possible that you need to define a macro to let the compiler know you intend to import symbols. Also, maybe the c10.lib you specified is a static library. See if there is another c10.lib elsewhere . – MorningDewd Nov 03 '20 at 11:32
  • I'm pretty sure the c10.lib file i specified is a index file to a c10.dll.And i have used the #pragma comment (lib, "c10.lib") macro but i still get this error. And if i don not specify this c10.lib i will get more link error – luffy Nov 03 '20 at 12:26
  • 1
    Have you set `Additonal Include Directories` in `Properties->C/C++`? Or you could check whether you are attempting to link 64-bit libraries to 32-bit code, or 32-bit libraries to 64-bit code. Also, you could refer to [Microsoft Docs](https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?view=msvc-160) for more information. – Barrnet Chou Nov 04 '20 at 02:34
  • Check if you are on Debug/Release, I see you have chosen `Release`, Select the `active` configuration, it prevents many silly mistakes, such as not setting the actual settings for the right configuration. Check and see if you have set the Additional Library Directories correctly. – Hossein Nov 05 '20 at 18:17

0 Answers0