Hello!
Background: I am working on a big-legacy code that runs on the VS 2015 (toolset v140), but not above. I want to merge this legacy code with the libtorch v2.0.1
Problem: I had no problem of compiling libtorch v2.0.1 on VS 2022 version. However, when I try to compile libtorch v2.0.1 on VS 2015, errors regarding “constexpr” show up.
I found a previous topic discussion related to this issue, but the discussion ended without any helpful replies.
https://discuss.pytorch.org/t/problems-compiling-with-libtorch-v1-5-0-and-vs-toolset-v140/82351
Following the previous post, I tried the minimal code below:
example-app.cpp
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
Warnings: (only the first one)
Severity Code Description Project File Line Suppression State
Warning C4814 'c10::reverse_iterator<_Iterator>::operator =': in C++14 'constexpr' will not imply 'const'; consider explicitly specifying 'const' minimal_2015ver_libtorch c:\users\user\downloads\common\libtorch-win-shared-with-deps-debug-2.0.1+cu118\libtorch\include\c10\util\reverse_iterator.h 88
Errors: (selecting first few errors)
Severity Code Description Project File Line Suppression State
Error C3249 illegal statement or sub-expression for 'constexpr' function minimal_2015ver_libtorch c:\users\user\downloads\common\libtorch-win-shared-with-deps-debug-2.0.1+cu118\libtorch\include\c10\core\dispatchkey.h 533
Error C3249 illegal statement or sub-expression for 'constexpr' function minimal_2015ver_libtorch c:\users\user\downloads\common\libtorch-win-shared-with-deps-debug-2.0.1+cu118\libtorch\include\c10\core\dispatchkey.h 532
Error C3250 'count': declaration is not allowed in 'constexpr' function body minimal_2015ver_libtorch c:\users\user\downloads\common\libtorch-win-shared-with-deps-debug-2.0.1+cu118\libtorch\include\c10\core\dispatchkey.h 560
Error C3249 illegal statement or sub-expression for 'constexpr' function minimal_2015ver_libtorch c:\users\user\downloads\common\libtorch-win-shared-with-deps-debug-2.0.1+cu118\libtorch\include\c10\core\dispatchkey.h 560
My environment:
Windows 11 Home
Compiler: VS 2022 version and VS 2015
I will appreciate any help, please.
Thanks,
Rak