Importing torch/script.h shows errors after building the project

I am using VS2019 to create a C++ DLL project that will use libtorch. I want to create two functions:

  • loadModel - that will load a .pt file
  • predictImage - that will evaluate the output for a given image
    I want to pack these two functions into a DLL for a further use in another programs.

I have set up my DLL project as follows:

  • I am using “libtorch-win-shared-with-deps-debug-1.6.0+cpu”
  • I only use one configuration - DEBUG CPU x64
  • In the property pages I have set-up the following changes:
    ---- Configuration Properties > General > C++ Language standard : ISO C++ 14
    ---- Configuration Properties > C/C++ > General > Additional Include Libraries:
    ------- Absolute path to libtorch\include
    ------- Aboslute path to libtorch\include\torch\csrc\api\include
    ---- Configuration Properties > C/C++ > General > SDL cheks: No
    ---- Configuration Properties > C/C++ > Language > Conformance Mode: No
    ---- Configuration Properties > Linker > General > Additional Library Directories:
    ------- Absolute path to libtorch\lib
    ---- Configuration Properties > Linker > Input > Additional Dependecies:
    ------- torch_cpu.lib
    ------- c10.lib
    ------- torch.lib
    ---- Configuration Properties > Build Events > Post-Build Event:
    ------- xcopy Absolute path to libtorch\lib*.dll $(SolutionDir)$(Platform)$(Configuration)\ /c /y

After setting this up, I can import the header files as normal, but building the project fails.
Just after including torch/script.h and buidling the project, I get a bunch of errors and warnings.

Another thing I have noticed is, that the IntelliSense will find the imported modules, and give me suggestions. For example, it allowed me to create a Module object my typing:
torch::jit::Module model;
Notice that there is no “script” between “jit” and “Module”, and the IntelliSense would show error.

When using torch::jit::load, the IntelliSense would give me a suggestion for the load function, but as soon as I type it, it will show me an error that “jit has no method called load”.

Again I cannot see if the declaration of the model variable or loading of the model works, since I cannot build the solution.

I am doing something wrong with setting up the project? I appreciate all the help. Thanks!