Cannot compile TorchScript C++ demo

username: ShannonZ
cooked: <p><strong>OS: Win10 x64</strong><br>
<strong>LibTorch Version: 1.3.1</strong><br>
I downloaded libtorch from the following links:</p>
<pre><code class="lang-auto">Download here (Release version):
https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-1.3.1.zip

Download here (Debug version):
https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-debug-1.3.1.zip
</code></pre>
<p>Then I add a new console application  in VS2017 community edition. The whole solution contains only a main.cpp:</p>
<pre><code class="lang-auto">#include &lt;torch/script.h&gt; // One-stop header.

#include &lt;iostream&gt;
#include &lt;memory&gt;

int main(int argc, const char* argv[]) {
  if (argc != 2) {
    std::cerr &lt;&lt; "usage: example-app &lt;path-to-exported-script-module&gt;\n";
    return -1;
  }


  torch::jit::script::Module module;
  try {
    // Deserialize the ScriptModule from a file using torch::jit::load().
    module = torch::jit::load(argv[1]);
  }
  catch (const c10::Error&amp; e) {
    std::cerr &lt;&lt; "error loading the model\n";
    return -1;
  }

  std::cout &lt;&lt; "ok\n";
}
</code></pre>
<p>(from this <a href="https://pytorch.org/tutorials/advanced/cpp_export.html#a-minimal-c-application" rel="noopener nofollow ugc">tutorial</a>: <a href="https://pytorch.org/tutorials/advanced/cpp_export.html#a-minimal-c-application" class="inline-onebox" rel="noopener nofollow ugc">Loading a TorchScript Model in C++ — PyTorch Tutorials 2.2.0+cu121 documentation</a>)</p>
<p>Then I add the include folders and lib directories. But I cannot successfully compile this solution. The error saying:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/7/778e6f890d0533265753eda961f1715a4d065014.png" data-download-href="https://discuss.pytorch.org/uploads/default/778e6f890d0533265753eda961f1715a4d065014" title="error_log"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/7/778e6f890d0533265753eda961f1715a4d065014_2_690x439.png" alt="error_log" data-base62-sha1="h3DZ8iOIKcQaK4M0NtarmtPaD52" width="690" height="439" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/7/778e6f890d0533265753eda961f1715a4d065014_2_690x439.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/7/778e6f890d0533265753eda961f1715a4d065014_2_1035x658.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/7/7/778e6f890d0533265753eda961f1715a4d065014_2_1380x878.png 2x" data-dominant-color="747575"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">error_log</span><span class="informations">1558×993 62.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I’ve googled this issue several days, but I still not find the key to it.<br>
I’ve checked the Release/Debug mode, set off the Conformance mode, compile libtorch from source…<br>
all failed.</p>
<p>Can anyone help me solve this problem? Any suggestions will be apreciated!</p>

username: Yitao_Sun
cooked: <p>The code is trying to load a Pytorch model from a directory, I’m little confused with what you mean by torchscript.</p>

username: ShannonZ
cooked: <p>Compile failure.<br>
Before load a pytorch model, the solution should be compiled successfully.</p>

username: Yitao_Sun
cooked: <p>Did you go through the CMake setup before compile this script?</p>