Compiling Libtorch tutorial example on Windows

username: Haydnspass
cooked: <p>Hey,</p>
<p>I try to compile the dummy example from the tutorial on Windows (on Linux / Mac everything works fine).<br>
For this I downloaded the Debug and Release versions for windows as they are provided and while cmake works fine, building the thing then does not work.</p>
<p>My cMake command:</p>
<pre><code class="lang-auto"> cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:/[path]/libtorch-win-shared-with-deps-1.2.0/libtorch -DCMAKE_BUILD_TYPE=Debug ..
</code></pre>
<p>The output of cmake is:</p>
<pre><code class="lang-auto">$ cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch -DCMAKE_BUILD_TYPE=Debug ..
-- The C compiler identification is MSVC 19.16.27024.1
-- The CXX compiler identification is MSVC 19.16.27024.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0 (found version "10.0")
-- Caffe2: CUDA detected: 10.0
-- Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/nvcc.exe
-- Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0
-- Caffe2: Header version is: 10.0
-- Found CUDNN: C:/ProgramData/NVIDIA GPU Computing Toolkit/v10.0/include
-- Found cuDNN: v7.6.3  (include: C:/ProgramData/NVIDIA GPU Computing Toolkit/v10.0/include, library: C:\ProgramData\NVIDIA GPU Computing Toolkit\v10.0\lib\x64)
CMake Warning (dev) at C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Caffe2/public/cuda.cmake:377 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:4 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Autodetected CUDA architecture(s):  5.0
-- Added CUDA NVCC flags for: -gencode;arch=compute_50,code=sm_50
CMake Warning (dev) at C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Caffe2/public/utils.cmake:57 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:121 (caffe2_interface_library)
  C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:4 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/share/cmake/Torch/TorchConfig.cmake:90 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeLists.txt:4 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found torch: C:/Users/Lucas/Documents/Repositories/InferenceSMLM/lib_external/libtorch-win-shared-with-deps-1.2.0/libtorch/lib/torch.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Lucas/Documents/Repositories/dummy/build


</code></pre>
<p>I then go to the build folder and open the .sln file in Visual studio 2017 and try to build it. VS then outputs:</p>
<pre><code class="lang-auto">1&gt;------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
2&gt;------ Build started: Project: dcgan, Configuration: Debug x64 ------
2&gt;LINK : fatal error LNK1104: cannot open file 'torch-NOTFOUND.obj'
2&gt;Done building project "dcgan.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
</code></pre>
<p>Can someone provide me with a hint? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Joey_Guo
cooked: <p>I met with the same problem. It works in <em>Release</em> mode, but not <em>Debug</em> mode.</p>
<p>Following the instructions at <a href="https://stackoverflow.com/questions/59006561/using-a-pytorch-model-in-c-application-on-windows" rel="nofollow noopener">https://stackoverflow.com/questions/59006561/using-a-pytorch-model-in-c-application-on-windows</a> , I finnally managed to get it work.</p>