Issues setting up LibTorch on Windows 11

Evan_Abbott: <p>Hello and thanks in advance,</p>
<p>I’ve been trying to set up LibTorch on Windows 11 by following the official PyTorch guide for <strong>“Installing C++ Distributions of PyTorch”</strong>. I have come across three to four issues trying to follow this. I only include the first two in case someone finds this by Google.<br>
<br>
</p>
<p><strong>Issue 1 (resolved):</strong></p>
<p>I learned from <a href="https://github.com/pytorch/pytorch/issues/12449" rel="noopener nofollow ugc">one thread</a> that I had to specify the Torch_DIR to the <code>TorchConfig.cmake</code> and <code>torch-config.cmake</code> files. This effectively replaced the command</p>
<p><code>cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..</code></p>
<p>to</p>
<p><code>cmake -DCMAKE_PREFIX_PATH=C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121 -DTorch_DIR=C:\Users\evana\Documents\MyPrograms\C++\Chess2\libtorch-win-shared-with-deps-2.2.1+cu121\libtorch\share\cmake\Torch ..</code></p>
<p><strong>Issue 2 (resolved):</strong></p>
<p>Even after including Torch_DIR in the command, I received the same error found in <a href="https://discuss.pytorch.org/t/failed-to-find-nvtoolsext/179635">this post</a>. I could be completely misunderstanding this, but I think that one of CUDA’s 12.1 libraries’ new header-only format was conflicting with LibTorch or one of its dependencies.<br>
<br>
The post helped me realize I had to use part of the CUDA 11.8 library.</p>
<p><strong>Issue 3:</strong></p>
<p>Finally, I could enter the first CMake command of the guide without errors:</p>
<pre><code class="lang-auto">PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build&gt; cmake -DCMAKE_PREFIX_PATH=C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121 -DTorch_DIR=C:\Users\evana\Documents\MyPrograms\C++\Chess2\libtorch-win-shared-with-deps-2.2.1+cu121\libtorch\share\cmake\Torch ..
&gt;&gt;
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.29.30153.0
-- The CXX compiler identification is MSVC 19.29.30153.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1 (found version "12.1") 
-- The CUDA compiler identification is NVIDIA 12.1.66
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/include (found version "12.1.66") 
-- Caffe2: CUDA detected: 12.1
-- Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/bin/nvcc.exe
-- Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1
-- Caffe2: Header version is: 12.1
-- C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/nvrtc.lib shorthash is bac8224f
-- USE_CUDNN is set to 0. Compiling without cuDNN support
-- USE_CUSPARSELT is set to 0. Compiling without cuSPARSELt support
-- Autodetected CUDA architecture(s):  8.6
-- Added CUDA NVCC flags for: -gencode;arch=compute_86,code=sm_86
-- Found Torch: C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121/libtorch/lib/torch.lib  
-- Configuring done (23.9s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/evana/Documents/MyPrograms/C++/Chess2/build
</code></pre>
<p>However, there was a problem with the second CMake command:</p>
<pre><code class="lang-auto">PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build&gt; cmake --build . --config Release                                                                                                                                                    
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  1&gt;Checking Build System
  Building Custom Rule C:/Users/evana/Documents/MyPrograms/C++/Chess2/CMakeLists.txt
  example-app.cpp
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\glog/log_severity.h(57,1): fatal error C1189: #error:  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document
 for detail. [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
</code></pre>
<p><strong>Issue 4:</strong></p>
<p>When I threw in a <code>#define GLOG_NO_ABBREVIATED_SEVERITIES</code> in <code>logging.h</code> to arbitrarily define the variable, I recieved over 100 syntax errors across multiple of LibTorch’s dependencies:</p>
<pre><code class="lang-auto">PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build&gt; cmake --build . --config Release                                                                                                                                                    
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

 1&gt;Checking Build System
 Building Custom Rule C:/Users/evana/Documents/MyPrograms/C++/Chess2/CMakeLists.txt
 example-app.cpp
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065,1): error C2589: '(': illegal token on right side of '::' [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065): error C2062: type 'unknown-type' unexpected [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065,1): error C2059: syntax error: ')' [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
... many more syntax errors later ...
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\ATen/core/jit_type_base.h(87,1): fatal error C1003: error count exceeds 100; stopping compilation [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-a 
pp.vcxproj]
</code></pre>
<p><strong>Code and other information:</strong><br>
I’m certain I’m overcomplicating things, but I’ve tried to stay as close as possible to the original guide for installing LibTorch on Windows 11. The code for <code>CMakeLists.txt</code> and <code>example-app.cpp</code> can be seen in the guide. As of March 17, 2024, I am using the most recent GPU, CUDA 12.1, Windows, C++ API combination: <code>libtorch-win-shared-with-deps-2.2.1+cu121.zip</code>.<br>
<br>
<br>
I greatly appreciate any help with issues 3 and 4! I can provide any more information as necessary.</p>

Evan_Abbott: <p>Ok so turns out Windows just isn’t the way to go when installing LibTorch. Instead, I spent $130 on a SSD and did a dual boot between my Windows 11 and Ubuntu 22.04. I followed <a href="https://www.youtube.com/watch?v=lI3ywh636IU&amp;pp=ygUQYnJpdGVjIGR1YWwgYm9vdA%3D%3D" rel="noopener nofollow ugc">this tutorial</a>. Then I just repeated the process in Linux.</p>
<p>I never tried installing LibTorch on Windows 11 using Visual Studio, because I wanted to do it through CMake; you may be able to install LibTorch through Visual Studio, idk</p>