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)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
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 https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET example-app
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:example-app>)
endif (MSVC)
target_link_libraries(AudioPluginExample
PRIVATE
# AudioPluginData # If we'd created a binary data target, we'd link to it here
juce::juce_audio_utils
"${TORCH_LIBRARIES}"
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)
It compiles fine, but upon trying to open the standalone, I get the usual “torch_cpu.dll not found”. If I move all the libtorch .dll files in the same directory as the executable, it opens just fine. But the VST3 obviously won’t open.
On windows you would put asmjit.dll, c10.dll, fbgemm.dll, libiomp5md.dll, torch.dll, torch_cpu.dll, uv.dll (and required vcruntimes) into the folder where your vst dynamic library file is.