Compiler report "'std': ambiguous symbol" error under Visual C++ 2017


(ZhengLi) #1

I download the pre-build distribution from https://pytorch.org/get-started/locally/(Stable-Windows-LibTorch-CUDA 10.0 version),I extract the zip file and add the inc/lib path to my VC2017 project,I write below code to test LibTorch:

#include <torch/script.h>
#include
#include

int main()
{
std::shared_ptrtorch::jit::script::Module model = torch::jit::load(“tmodel.pt”);
std::cout << “Hello World!\n”;
return 0;
}

but compile failed,the compiler report below errors:
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 461
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h 15
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h 21
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h 28
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h 35
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h 42
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 162
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 166
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 170
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 174
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 177
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 180
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 234
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 441
Error C2872 ‘std’: ambiguous symbol TestLibTorch1 g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h 451

the error says std is ambiguous symbol,what is the meaning? How to fix these errors?


(Pu Jiachen) #2

(ZhengLi) #3

You mean it is a bug of current version libtorch?


(Pu Jiachen) #4

Yes, actually you can fix that manually by prepending :: before std in these headers.


(ZhengLi) #5

OK,I understand,thank you!