Using LibTorch with JUCE

Hi, I’m trying to create a plugin in JUCE which uses pytorch. The C++ distribution of pytorch, ‘libtorch’, is described here:

What I’m struggling with is how to include the libtorch library in my JUCE project. I have successfully included other third party libraries, by adding the library directory to the projucer and using an include statement on the header file. However, for libtorch there doesn’t seem to be a header file that I can just include, the recommended installation process involves using CMake. Is there a way I can use this library within projucer/xcode?


Is it too late to switch from Projucer to CMake as your build tool? You can use this example JUCE-CMake plugin project as a template, then add the following lines to CMakeLists.txt (taken directly from the libtorch installation link you included)

find_package(Torch REQUIRED)

target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

# The following code block is suggested to be used on Windows.
# According to,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
  add_custom_command(TARGET example-app
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
endif (MSVC)

Thanks, I will have a go at this. I didn’t realise there were CMake examples available!