Libtorch + C++17 + Visual Studio

Hello all,

Windows 10
CUDA 10.1
CuDNN 7.6.5
libtorch from pytorch website, release mode (latest stable one)

I am able to use libtorch in a separate Visual Studio 2017 project and do the inference.

However, I need to link libtorch to another project which is using C++17 and I get deprecation errors like this:

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	

In my own code, I disable this warning at the beginning of the header file that includes and uses the libtorch library:

#pragma once
#pragma warning (push)
#pragma warning(disable: 4996)
// code
#include <torch/script.h>
#pragma warning (pop)

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?

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 ?

Thank you for your response.

I was previously following this link and hence was using #pragma warning (disable…)

Following user_defined_macros, I still get the same deprecation errors.

I set the name to _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING and value to 1. Also tried silence all, but nothing changes.

OK, so I figured it out:

Go to Project Properties -> Configuration Properties -> C/C++ -> Advanced -> Disable Specific Warnings and add 4996.

I am facing the exact same issue, however, the solution provided here does not work in my case.
I am using libtorch 1.6 and VC 19.

There are 2473 errors …

It works with ISO C++17 Standard (/std:c++17) but NOT with (/std:c++latest) which is what I must have.

Any ideas?