Compiling Libtorch tutorial example on Windows

Hey,

I try to compile the dummy example from the tutorial on Windows (on Linux / Mac everything works fine).
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.

My cMake command:

 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 ..

The output of cmake is:

$ 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


I then go to the build folder and open the .sln file in Visual studio 2017 and try to build it. VS then outputs:

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
2>------ Build started: Project: dcgan, Configuration: Debug x64 ------
2>LINK : fatal error LNK1104: cannot open file 'torch-NOTFOUND.obj'
2>Done building project "dcgan.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can someone provide me with a hint? :slight_smile:

I met with the same problem. It works in Release mode, but not Debug mode.

Following the instructions at https://stackoverflow.com/questions/59006561/using-a-pytorch-model-in-c-application-on-windows , I finnally managed to get it work.