title: Error Compiling C++/Cuda extension with Pytorch Cuda c++ in MSVC using CMake
body: <p>I am trying to build a c++/cuda extension with Pytorch following the tutorial <a href="https://pytorch.org/tutorials/advanced/cpp_extension.html" rel="nofollow noreferrer">here</a>, (with instructions how to use pytorch with c++ <a href="https://pytorch.org/cppdocs/installing.html#minimal-example" rel="nofollow noreferrer">here</a>). My environment details are:</p>
  <ul>
  <li>Using Microsoft Visual Studio 2019 version 16.6.5</li>
  <li>Windows 10</li>
  <li>libtorch c++ debug 1.70 with cuda 11.0 installed from the pytorch website</li>
  </ul>
  <p>I am using this cmake code where I set the include directory for python 3.6 and the library for python36.lib</p>
  <pre><code>cmake_minimum_required (VERSION 3.8)
  
  project (&quot;DAConvolution&quot;)
  
  find_package(Torch REQUIRED)
  
  # Add source to this project's executable.
  add_executable (DAConvolution &quot;DAConvolution.cpp&quot; &quot;DAConvolution.h&quot;)
  
  include_directories(&quot;C:/Users/James/Anaconda3/envs/masters/include&quot;)
     
  target_link_libraries(DAConvolution &quot;${TORCH_LIBRARIES}&quot; &quot;C:/Users/James/Anaconda3/envs/masters/libs/python36.lib&quot;)
  
  if (MSVC)
    file(GLOB TORCH_DLLS &quot;${TORCH_INSTALL_PREFIX}/lib/*.dll&quot;)
    add_custom_command(TARGET DAConvolution
                       POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
                       ${TORCH_DLLS}
                       $&lt;TARGET_FILE_DIR:DAConvolution&gt;)
  endif (MSVC)
  </code></pre>
  <p>I set the CMake command arguments to be -DCMAKE_PREFIX_PATH=C:\libtorch  (my path to libtorch debug mentioned above). I am building with the x64-debug option in MSVC version (as building with the x-64 Release option gives me a torch-NOTFOUND error).</p>
  <pre><code>The example DAConvolution.cpp file is:
  
  #ifdef _DEBUG
  #undef _DEBUG
  #include &lt;python.h&gt;
  #define _DEBUG
  #else
  #include &lt;python.h&gt;
  #endif
  
  #include &lt;torch/extension.h&gt;
  </code></pre>
  <p>Where I have undefined the _DEBUG flag so that the linker does not look for the python36_d.lib file (which I do not have).</p>
  <p>I am getting a linking error:</p>
  <p><a href="https://i.stack.imgur.com/ZqxUH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZqxUH.png" alt="enter image description here" /></a></p>
  <p>Simply including torch.h works fine, but when I want to include the extension header thats when I get these problems, as it uses Pybind 11 I believe. Any insights much appreciated. I have tried to include all the info I can, but would be happy to give more information.</p>