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

username: ItalianSC
cooked: <p>I download the pre-build distribution from <a href="https://pytorch.org/get-started/locally/" rel="nofollow noopener">https://pytorch.org/get-started/locally/</a>(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:</p>
<p><span class="hashtag">#include</span> &lt;torch/script.h&gt;<br>
<span class="hashtag">#include</span>  <br>
<span class="hashtag">#include</span>  </p>
<p>int main()<br>
{<br>
std::shared_ptr<a>torch::jit::script::Module</a> model = torch::jit::load(“tmodel.pt”);<br>
std::cout &lt;&lt; “Hello World!\n”;<br>
return 0;<br>
}</p>
<p>but compile failed,the compiler report below errors:<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	461	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h	15	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h	21	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h	28	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h	35	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\jit\custom_operator.h	42	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	162	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	166	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	170	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	174	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	177	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	180	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	234	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	441	<br>
Error	C2872	‘std’: ambiguous symbol	TestLibTorch1	g:\vc15\testlibtorch\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	451</p>
<p>the error says std is ambiguous symbol,what is the meaning? How to fix these errors?</p>

username: peterjc123
cooked: <aside class="onebox githubpullrequest">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/pull/17863" target="_blank" rel="nofollow noopener">github.com/pytorch/pytorch</a>
  </header>
  <article class="onebox-body">
      <a href="https://github.com/peterjc123" target="_blank" rel="nofollow noopener">
    <img alt="peterjc123" src="https://avatars3.githubusercontent.com/u/9998726?v=4" class="thumbnail onebox-avatar" width="90" height="90">
  </a>

<h4>
  <a href="https://github.com/pytorch/pytorch/pull/17863" target="_blank" rel="nofollow noopener">Prevent VS2017 from emitting ambiguous symbol errors (second time)</a>
</h4>

<div class="date">
  by <a href="https://github.com/peterjc123" target="_blank" rel="nofollow noopener">peterjc123</a>
  on <a href="https://github.com/pytorch/pytorch/pull/17863" target="_blank" rel="nofollow noopener">09:31AM - 11 Mar 19 UTC</a>
</div>

<div class="github-commit-stats">
  <strong>1 commits</strong>
  changed <strong>2 files</strong>
  with <strong>15 additions</strong>
  and <strong>15 deletions</strong>.
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: ItalianSC
cooked: <p>You mean it is a bug of current version libtorch?</p>

username: peterjc123
cooked: <p>Yes, actually you can fix that manually by prepending :: before std in these headers.</p>

username: ItalianSC
cooked: <p>OK,I understand,thank you!</p>

username: msminhas93
cooked: <p>I faced the same issue in Visual Studio 2019.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/6/3615f96abab2d04e5b3acdd1077cffae0c898419.png" data-download-href="https://discuss.pytorch.org/uploads/default/3615f96abab2d04e5b3acdd1077cffae0c898419" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/6/3615f96abab2d04e5b3acdd1077cffae0c898419.png" alt="image" data-base62-sha1="7IsRvJ4bxQQuJePWWiz6eVETPO9" width="690" height="203" data-dominant-color="F2F3F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1069×316 5.41 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>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-)</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/1/3116b2bebc9d3a86f8c830393c6af0de47e45f34.png" data-download-href="https://discuss.pytorch.org/uploads/default/3116b2bebc9d3a86f8c830393c6af0de47e45f34" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/1/3116b2bebc9d3a86f8c830393c6af0de47e45f34_2_690x226.png" alt="image" data-base62-sha1="70g1EU76o75Co8pDdgBtUz323Na" width="690" height="226" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/1/3116b2bebc9d3a86f8c830393c6af0de47e45f34_2_690x226.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/1/3116b2bebc9d3a86f8c830393c6af0de47e45f34_2_1035x339.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/1/3116b2bebc9d3a86f8c830393c6af0de47e45f34_2_1380x452.png 2x" data-dominant-color="F5F7F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1477×484 17.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>The default value has changed from no value to Yes(/premissive-) from Visual Studio 2017 onwards. More details can be found on this page. <a href="https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2019" class="inline-onebox" rel="noopener nofollow ugc">/permissive- (Standards conformance) | Microsoft Learn</a></p>
<p>Changing the value to No solved the problem for me.</p>
<p>Hope this helps someone!</p>

username: ran_zhuo
cooked: <p>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</p>