How to run libtorch on Visual Studio

Hi, does anyone know here, how to run libtorch on Visual Studio? I get linker errors although I fed the libtorch file into C++ and linker directories. I followed the tutorial, where Cmake is used but is it really necessary? I just want to hit the play button and get things done. No release build, no other build. Just run the code.

I think the link error probably is because that official libtorch is built using gcc 4.x for compatibility and some dependencies of your project is built using gcc 5.x or higher version.

Try to build libtorch from source?

Hi, thanks for your advice. How do I do this? I already read, that there is an opportunity to build from libtorch source, but to be honest I don’t have a clue what it means. Could you explain it briefly please :slight_smile: ?

If you project is linked with some other dependencies? The ABI issue won’t lead to link error(undefined reference to …) if you are just running C++ API example given in tutorials.

I only link libtorch on linux and don’t know much about how to link in windows.

There are no other dependencies there :frowning:

If that I think you need to check you VS configuration or search other tutorials about linking libtorch on Windows…

Hi, I am new to pytorch and I got confused about libtorch. After running build_libtorch.sh, how can I organize files like the one downloaded from homepage? Thanks.

You may use these commands:

cd [PYTORCH_ROOT_DIR]
mkdir -p libtorch/include && mkdir -p libtorch/share && mkdir -p libtorch/bin
cp -r build/lib libtorch
cp -r torch/share/cmake libtorch/share

for dir in ATen c10 caffe2 torch
do 
    cp -r torch/include/$dir libtorch/include
done

But I can’t make sure the official libtorch is built as above.

1 Like

Thank you! It works.