LibTorch C++ Windows exception in register_module()

Hello, Yesterday I’ve grabbed the stable version of Libtorch from Start Locally | PyTorch

it is “Stable (1.13.0) with Cuda 11.7 and with C++ for Windows”.

However getting an exception, when invoking register_module():

I’ve first tried building using the usual Visual Studio solution,
and then make a fresh project using a CMake file.

Strangely, getting the exact same behavior in either case. The libraries are connected, the include directories are specified, the code compiles. Until I try to construct the Net object

What might be happening? :thinking:

if we go down the call stack we see that the children_ OrderedDictionary has incorrect size and doesn’t appear to be initialized:

When we access it, it throws this error:

Sorry, I’m a new user so I couldn’t upload all 3 pictures into one post and had to split into several.

Caused by downloading the wrong version of Libtorch.
I was compiling stuff in Visual Studio solution in Debug mode, but downloaded Release mode of Libtorch from the website. Needed the Debug instead.

Did you achieve execute the program in release mode? i’m facing the same problem, it works fine in debug mode, but not in release when using the release distribution that you first downloaded. Tried with older release versions, but the problem persists

Yes, all works ok in release. In Visual Studio I specify the following as “Additional Include Directories”:

And the libraries I’m linking are:

Finally, I’m copying all the .dll files from C:\src\libtorch\Release\lib\ into the folder where my executable will be. I do it in Visual studio via Project Properties->Post-Build Events-> Command Line:

xcopy /y “C:\src\libtorch\Release\lib*.dll” "C:_myDrive\repos\harvest\Harvest\Release".

I’m using C++20 and the toolset, which the Libtorch doesn’t quite like, because it’s made for C++14. So I’m using a precompiled header (header that is included before any other header), where I wrap the #include <torch/torch> with several pragma-warning-disables.

Have you solved this problem now? I have also encountered this problem now