Libtorch + C++17 + Visual Studio

username: Shakiba_Kh
cooked: <p>Hello all,</p>
<p>environment:<br>
Windows 10<br>
CUDA 10.1<br>
CuDNN 7.6.5<br>
libtorch from pytorch website, release mode (latest stable one)</p>
<p>I am able to use libtorch in a separate Visual Studio 2017 project and do the inference.</p>
<p>However, I need to link libtorch to another project which is using C++17 and I get deprecation errors like this:</p>
<pre><code class="lang-auto">Error	C4996	'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are deprecated in C++17. They are superseded by std::invoke_result and std::invoke_result_t. You can define _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.	WeldVision	address\externals\libtorch\include\c10\util\c++17.h	34	
</code></pre>
<p>In my own code, I disable this warning at the beginning of the header file that includes and uses the libtorch library:</p>
<pre><code class="lang-auto">#pragma once
#pragma warning (push)
#pragma warning(disable: 4996)
// code
#include &lt;torch/script.h&gt;
//code
#pragma warning (pop)
</code></pre>
<p>But it is not working. Do you know how I can solve this problem and how can I use this library that is build with C++14 compatible with C++17?</p>

username: Sebastian_Messmer
cooked: <p>Try adding -D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING=1 to your build command. In Visual Studio, this is probably somewhere in the project settings, can you define a build macro _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING=1 ?</p>

username: Shakiba_Kh
cooked: <p>Thank you for your response.</p>
<p>I was previously following <a href="https://devblogs.microsoft.com/cppblog/c17-feature-removals-and-deprecations/" rel="nofollow noopener">this link</a> and hence was using <span class="hashtag">#pragma</span> warning (disable…)</p>
<p>Following <a href="https://docs.microsoft.com/en-us/cpp/build/working-with-project-properties?view=vs-2017#user-defined-macros" rel="nofollow noopener">user_defined_macros</a>, I still get the same deprecation errors.</p>
<p>I set the name to _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING and value to 1. Also tried silence all, but nothing changes.</p>

username: Shakiba_Kh
cooked: <p>OK, so I figured it out:</p>
<p>Go to Project Properties -&gt; Configuration Properties -&gt; C/C++ -&gt; Advanced -&gt; Disable Specific Warnings and add 4996.</p>

username: dambo
cooked: <p>Hello,<br>
I am facing the exact same issue, however, the solution provided here does not work in my case.<br>
I am using libtorch 1.6 and  VC 19.</p>
<p>There are 2473 errors …</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/2/62b63e4c34eaa4da812300ae617aacff2c73fa42.png" data-download-href="https://discuss.pytorch.org/uploads/default/62b63e4c34eaa4da812300ae617aacff2c73fa42" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/62b63e4c34eaa4da812300ae617aacff2c73fa42_2_632x500.png" alt="image" data-base62-sha1="e5ffif3ZGxvUhq61b9NC6hfmDcu" width="632" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/62b63e4c34eaa4da812300ae617aacff2c73fa42_2_632x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/62b63e4c34eaa4da812300ae617aacff2c73fa42_2_948x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/2/62b63e4c34eaa4da812300ae617aacff2c73fa42_2_1264x1000.png 2x" data-dominant-color="7C8481"><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">1287×1018 93.5 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>It works with ISO C++17 Standard (/std:c++17) but NOT with (/std:c++latest) which is what I must have.</p>
<p>Any ideas?</p>

username: Shakiba_Kh
cooked: <p><a class="mention" href="/u/dambo">@dambo</a> I could build my project successfully with /std:c++latest.<br>
My setup is VC 2017(version 15.9.22), Libtorch 1.4 - release version.</p>
<p>I still did not have time to check libtorch 1.6.</p>

username: dambo
cooked: <p>Yes … works with std++17 now.</p>