Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including LibTorch distrubution #578

Closed
julius-richter opened this issue Jan 10, 2020 · 5 comments
Closed

Including LibTorch distrubution #578

julius-richter opened this issue Jan 10, 2020 · 5 comments

Comments

@julius-richter
Copy link

Hello there,

first of all, thank you for implementing FRUT, it is very helpful :)

My question is: I want to include the library LibTorch to my JUCE project. The conversion to a cmake file from my .jucer project worked perfectly. Now, in the tutorial on how to include LibTorch to my application it is described that I need to write the following CMakeLists.txt

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(custom_ops)

find_package(Torch REQUIRED)

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)

So I put the four bottom lines to the automatically generated CMakeLists.txt. However, I get the following error when compiling. Do you have any idea what is the problem here?

-- Setting CMAKE_BUILD_TYPE to "Debug" as it was not specified.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/juliusrichter/Documents/Uni/Masterarbeit/beat_tracker/app/BeatTracker/build
[ 87%] Built target BeatTracker
Scanning dependencies of target Main
[ 93%] Building CXX object CMakeFiles/Main.dir/Source/Main.cpp.o
In file included from /Users/juliusrichter/Documents/Uni/Masterarbeit/beat_tracker/app/BeatTracker/Source/Main.cpp:1:
/Users/juliusrichter/Documents/Uni/Masterarbeit/beat_tracker/app/BeatTracker/Source/../JuceLibraryCode/JuceHeader.h:17:10: fatal error: 'juce_audio_basics/juce_audio_basics.h' file not found
#include <juce_audio_basics/juce_audio_basics.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/Main.dir/Source/Main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Main.dir/all] Error 2
make: *** [all] Error 2
[Finished in 1.8s with exit code 2]
[shell_cmd: cmake --build ../build --config Release]
[dir: /Users/juliusrichter/Documents/Uni/Masterarbeit/beat_tracker/app/BeatTracker/Source]
[path: /Applications/google-cloud-sdk/bin:/Users/juliusrichter/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/git/bin]

The full CMakeLists.txt looks like this:

# This file was generated by Jucer2Reprojucer from "BeatTracker.jucer"

cmake_minimum_required(VERSION 3.4)

project("BeatTracker")


list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../FRUT/prefix/FRUT/cmake")
include(Reprojucer)


find_package(Torch REQUIRED)

add_executable(Main "../Source/Main.cpp")
target_link_libraries(Main "${TORCH_LIBRARIES}")
set_property(TARGET Main PROPERTY CXX_STANDARD 11)


set(BeatTracker_jucer_FILE
  "${CMAKE_CURRENT_LIST_DIR}/BeatTracker.jucer"
)

set(JUCE_MODULES_GLOBAL_PATH "${CMAKE_CURRENT_LIST_DIR}/../JUCE/modules")


jucer_project_begin(
  JUCER_VERSION "5.4.5"
  PROJECT_FILE "${BeatTracker_jucer_FILE}"
  PROJECT_ID "xW1TAG"
)

jucer_project_settings(
  PROJECT_NAME "BeatTracker"
  PROJECT_VERSION "0.0.1"
  COMPANY_NAME "JUCE"
  COMPANY_WEBSITE "http://juce.com"
  REPORT_JUCE_APP_USAGE ON # Required for closed source applications without an Indie or Pro JUCE license
  DISPLAY_THE_JUCE_SPLASH_SCREEN ON # Required for closed source applications without an Indie or Pro JUCE license
  PROJECT_TYPE "GUI Application"
  BUNDLE_IDENTIFIER "com.JUCE.BeatTracker"
  CXX_LANGUAGE_STANDARD "C++14"
  # PREPROCESSOR_DEFINITIONS
  # NOTES
  #   Plays audio files.
)

jucer_project_files("BeatTracker/Source"
# Compile   Xcode     Binary    File
#           Resource  Resource
  x         .         .         "Source/Main.cpp"
  .         .         .         "Source/BeatTracker.h"
)

jucer_project_module(
  juce_audio_basics
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
)

jucer_project_module(
  juce_audio_devices
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_USE_WINRT_MIDI
  # JUCE_ASIO
  # JUCE_WASAPI
  # JUCE_WASAPI_EXCLUSIVE
  # JUCE_DIRECTSOUND
  # JUCE_ALSA
  # JUCE_JACK
  # JUCE_BELA
  # JUCE_USE_ANDROID_OBOE
  # JUCE_USE_ANDROID_OPENSLES
  # JUCE_DISABLE_AUDIO_MIXING_WITH_OTHER_APPS
)

jucer_project_module(
  juce_audio_formats
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_USE_FLAC
  # JUCE_USE_OGGVORBIS
  # JUCE_USE_MP3AUDIOFORMAT
  # JUCE_USE_LAME_AUDIO_FORMAT
  # JUCE_USE_WINDOWS_MEDIA_FORMAT
)

jucer_project_module(
  juce_audio_processors
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_PLUGINHOST_VST
  # JUCE_PLUGINHOST_VST3
  # JUCE_PLUGINHOST_AU
  # JUCE_PLUGINHOST_LADSPA
)

jucer_project_module(
  juce_audio_utils
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_USE_CDREADER
  # JUCE_USE_CDBURNER
)

jucer_project_module(
  juce_core
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_FORCE_DEBUG
  # JUCE_LOG_ASSERTIONS
  # JUCE_CHECK_MEMORY_LEAKS
  # JUCE_DONT_AUTOLINK_TO_WIN32_LIBRARIES
  # JUCE_INCLUDE_ZLIB_CODE
  # JUCE_USE_CURL
  # JUCE_LOAD_CURL_SYMBOLS_LAZILY
  # JUCE_CATCH_UNHANDLED_EXCEPTIONS
  # JUCE_ALLOW_STATIC_NULL_VARIABLES
  # JUCE_STRICT_REFCOUNTEDPOINTER
)

jucer_project_module(
  juce_data_structures
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
)

jucer_project_module(
  juce_dsp
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_ASSERTION_FIRFILTER
  # JUCE_DSP_USE_INTEL_MKL
  # JUCE_DSP_USE_SHARED_FFTW
  # JUCE_DSP_USE_STATIC_FFTW
  # JUCE_DSP_ENABLE_SNAP_TO_ZERO
)

jucer_project_module(
  juce_events
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_EXECUTE_APP_SUSPEND_ON_IOS_BACKGROUND_TASK
)

jucer_project_module(
  juce_graphics
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_USE_COREIMAGE_LOADER
  # JUCE_USE_DIRECTWRITE
  # JUCE_DISABLE_COREGRAPHICS_FONT_SMOOTHING
)

jucer_project_module(
  juce_gui_basics
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_ENABLE_REPAINT_DEBUGGING
  # JUCE_USE_XRANDR
  # JUCE_USE_XINERAMA
  # JUCE_USE_XSHM
  # JUCE_USE_XRENDER
  # JUCE_USE_XCURSOR
  # JUCE_WIN_PER_MONITOR_DPI_AWARE
)

jucer_project_module(
  juce_gui_extra
  PATH "${JUCE_MODULES_GLOBAL_PATH}"
  # JUCE_WEB_BROWSER
  # JUCE_ENABLE_LIVE_CONSTANT_EDITOR
)

jucer_export_target(
  "Xcode (MacOSX)"
)

jucer_export_target_configuration(
  "Xcode (MacOSX)"
  NAME "Debug"
  DEBUG_MODE ON
  BINARY_NAME "BeatTracker"
  OPTIMISATION "-O0 (no optimisation)"
)

jucer_export_target_configuration(
  "Xcode (MacOSX)"
  NAME "Release"
  DEBUG_MODE OFF
  BINARY_NAME "BeatTracker"
  OPTIMISATION "-O3 (fastest with safe optimisations)"
)

jucer_export_target(
  "Visual Studio 2017"
)

jucer_export_target_configuration(
  "Visual Studio 2017"
  NAME "Debug"
  DEBUG_MODE ON
  BINARY_NAME "BeatTracker"
  OPTIMISATION "No optimisation"
)

jucer_export_target_configuration(
  "Visual Studio 2017"
  NAME "Release"
  DEBUG_MODE OFF
  BINARY_NAME "BeatTracker"
  OPTIMISATION "Maximise speed"
)

jucer_export_target(
  "Linux Makefile"
)

jucer_export_target_configuration(
  "Linux Makefile"
  NAME "Debug"
  DEBUG_MODE ON
  BINARY_NAME "BeatTracker"
  OPTIMISATION "-O0 (no optimisation)"
)

jucer_export_target_configuration(
  "Linux Makefile"
  NAME "Release"
  DEBUG_MODE OFF
  BINARY_NAME "BeatTracker"
  OPTIMISATION "-O3 (fastest with safe optimisations)"
)

jucer_project_end()
@McMartin
Copy link
Owner

McMartin commented Jan 11, 2020

Hi @julius-richter,

first of all, thank you for implementing FRUT, it is very helpful :)

Thank you for trying to use FRUT! Please consider starring it to increase its visibility on GitHub.

Do you have any idea what is the problem here?

The lines that you added are completely disconnected from the rest of the contents of the generated CMakeLists.txt. You would get the same result by having only these lines in a new CMakeLists.txt file.

Now, let's attempt to fix your problem:

  • I'm guessing that you want to use libtorch in your BeatTracker application, and not make a new Main (console) executable.
  • jucer_project_end adds a regular CMake target called BeatTracker. This means that you can use it like any CMake target after calling jucer_project_end().
  • The TorchConfig.cmake file defines an imported target (called torch) that you can use instead of dealing manually with the variables TORCH_INCLUDE_DIRS and TORCH_LIBRARIES.

Based on that, this is how I would change the contents of the CMakeLists.txt file that you pasted:

@@ -10,10 +10,6 @@
 
 
 find_package(Torch REQUIRED)
-
-add_executable(Main "../Source/Main.cpp")
-target_link_libraries(Main "${TORCH_LIBRARIES}")
-set_property(TARGET Main PROPERTY CXX_STANDARD 11)
 
 
 set(BeatTracker_jucer_FILE
@@ -222,3 +218,6 @@
 )
 
 jucer_project_end()
+
+
+target_link_libraries(BeatTracker PRIVATE torch)

I hope this helps!

@julius-richter
Copy link
Author

Hi @McMartin,

thank you so much for your help. Now it works.

All the best, Julius

@McMartin
Copy link
Owner

You're welcome!
Feel free to create new issues if you encounter any problems.
Cheers

@Nintorac
Copy link

Nintorac commented Jun 6, 2020

Hey,

I am trying to do this as well however I get an error like this Cannot specify link libraries for target "NeuralDX7" which is not built this project.

NeuralDX7 is the name of the project.

Additionally is it possible to add this through the projucer so I don't need to manually add to the cmake after running Frut?

@McMartin
Copy link
Owner

McMartin commented Jun 6, 2020

Hi @Nintorac,

I guess that project is not a GUI Application but an Audio Plug-In. In that case, you should use:

target_link_libraries(NeuralDX7_Shared_Code PUBLIC torch)

You can indeed try to add libtorch to your project in Projucer, but it won't be as easy as adding a single line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants