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

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?

You mean it is a bug of current version libtorch?

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

1 Like

OK,I understand,thank you!

I faced the same issue in Visual Studio 2019.

The errors in my case were because of a problem with one of the C++ project properties. Specifically Properties → C/C++ → Language → Conformance mode → Yes(/permissive-)

The default value has changed from no value to Yes(/premissive-) from Visual Studio 2017 onwards. More details can be found on this page. https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2019

Changing the value to No solved the problem for me.

Hope this helps someone!

It happened not only in MSVC,but also on Linux. I used VS connected to the WSL with libtorch LTS, it happened the same problem