Skip to content

Using your environment

Building FluidSynth with CMake

Let's return to our original goal of compiling FluidSynth using CMake as per its official documentation.

To keep this example simple, we are not using any listed optional libraries. If you needed them you could either check if Spack can provide them (either from upstream or as a personal install), or manually compile them as needed.

In the activated environment:

Building FluidSynth with CMake (click to expand output)
[spack-cmake] $ cd /data/scratch/${USER}
[spack-cmake] $ wget https://github.com/FluidSynth/fluidsynth/archive/refs/tags/v2.4.2.tar.gz
...
Saving to: ‘v2.4.2.tar.gz’
...
‘v2.4.2.tar.gz’ saved [1785003]

[spack-cmake] $ tar -xvf v2.4.2.tar.gz
...
[spack-cmake] $ cd fluidsynth-2.4.2
[spack-cmake] [fluidsynth-2.4.2]$ mkdir build
[spack-cmake] [fluidsynth-2.4.2]$ cd build

[spack-cmake] [build]$ cmake \
                       -DCMAKE_INSTALL_PREFIX=/data/scratch/${USER}/fluidsynth-install \
                       -DCMAKE_C_COMPILER=gcc \
                       -DCMAKE_CXX_COMPILER=g++ \
                       ..
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /data/home/abc123/scratch/spack-environments/spack-cmake/.spack-env/view/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /data/home/abc123/scratch/spack-environments/spack-cmake/.spack-env/view/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking whether system has ANSI C header files
-- Looking for 8 include files dlfcn.h, ..., float.h
-- Looking for 8 include files dlfcn.h, ..., float.h - found
-- Performing Test memchrExists
-- Performing Test memchrExists - Success
-- Performing Test freeExists
-- Performing Test freeExists - Success
-- ANSI C header files - found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for DIR in sys/stat.h;sys/types.h;dirent.h
-- Looking for DIR in sys/stat.h;sys/types.h;dirent.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for sys/socket.h
-- Looking for sys/socket.h - found
-- Looking for netinet/in.h
-- Looking for netinet/in.h - found
-- Looking for netinet/tcp.h
-- Looking for netinet/tcp.h - found
-- Looking for arpa/inet.h
-- Looking for arpa/inet.h - found
-- Looking for limits.h
-- Looking for limits.h - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for signal.h
-- Looking for signal.h - found
-- Looking for getopt.h
-- Looking for getopt.h - found
-- Check size of long long
-- Check size of long long - done
-- Performing Test _have_inline
-- Performing Test _have_inline - Success
-- Performing Test _have_vla
-- Performing Test _have_vla - Success
-- Performing Test HAVE_INCOMPATIBLE_POINTER_TYPES
-- Performing Test HAVE_INCOMPATIBLE_POINTER_TYPES - Success
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found GLib2: /data/home/abc123/scratch/spack-environments/spack-cmake/.spack-env/view/lib/libglib-2.0.so (found suitable version "2.78.3", minimum required is "2.6.5")
-- Could NOT find SndFileLegacy (missing: _sndfile_library SndFile_INCLUDE_DIR)
-- Could NOT find SndFile (Set SndFile_DIR to the directory containing its CMake config) (Required is at least version 1.0.0)
-- Could NOT find PulseAudio (Set PulseAudio_DIR to the directory containing its CMake config) (Required is at least version 2.0)
-- Could NOT find ALSA (missing: ALSA_LIBRARY ALSA_INCLUDE_DIR) (Required is at least version "0.9.1")
-- Could NOT find Jack (missing: Jack_LIBRARY Jack_INCLUDE_DIR)
-- Could NOT find PipeWire (missing: PipeWire_LIBRARY PipeWire_INCLUDE_DIR Spa_INCLUDE_DIR) (Required is at least version "0.3")
-- Could NOT find Systemd (missing: Systemd_LIBRARY Systemd_INCLUDE_DIR)
-- Could NOT find DBus1 (Set DBus1_DIR to the directory containing its CMake config)
-- Looking for ladspa.h
-- Looking for ladspa.h - not found
-- Could NOT find InstPatch (missing: InstPatch_LIBRARY InstPatch_INCLUDE_DIR) (Required is at least version "1.1.0")
-- Could NOT find SDL2 (Set SDL2_DIR to the directory containing its CMake config)
-- Found Readline: /data/home/abc123/scratch/spack-environments/spack-cmake/.spack-env/view/lib/libreadline.so (found version "8.2")
-- Looking for sys/soundcard.h
-- Looking for sys/soundcard.h - found
-- Looking for linux/soundcard.h
-- Looking for linux/soundcard.h - found
-- Looking for machine/soundcard.h
-- Looking for machine/soundcard.h - not found
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5") found components: C
-- Found OpenMP version: 4.5 date: 201511
-- Looking for sinf
-- Looking for sinf - found
-- Looking for cosf
-- Looking for cosf - found
-- Looking for fabsf
-- Looking for fabsf - found
-- Looking for powf
-- Looking for powf - found
-- Looking for sqrtf
-- Looking for sqrtf - found
-- Looking for logf
-- Looking for logf - found
-- Looking for inet_ntop
-- Looking for inet_ntop - found
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
--
**************************************************************
Build Summary:
FluidSynth Version:    2.4.2
Library version:       3.3.2
Git revision:          not a git working copy
Build type:            RelWithDebInfo
Install Prefix:        /data/scratch/abc123/fluidsynth-install

Audio / MIDI driver support:
  ALSA:                  no
  CoreAudio:             no
  CoreMIDI:              no
  DSound:                no
  JACK:                  no
  MidiShare:             no
  Oboe:                  no
  OpenSLES:              no
  OS/2 DART:             no
  OS/2 KAI:              no
  OSS:                   yes
  PipeWire:              no
  PortAudio:             no
  PulseAudio:            no
  SDL2:                  no
  WASAPI:                no
  WaveOut:               no
  WinMidi:               no

Support for SF3 files:   no (libsndfile not found)
Support for DLS files:   no (libinstpatch not found)

Audio to file rendering: yes
  libsndfile:            no (RAW PCM rendering only)

Miscellaneous support:
  D-Bus:                 no
  LADSPA support:        no
  NETWORK Support:       yes
    IPV6 Support:        yes
  Readline:              yes (NOTE: GPL library)
  systemd:               no
  getopt:                yes

Developer nerds info:
  Samples type:          double
  Multithread rendering: yes
  OpenMP 4.0:            yes
  Profiling:             no
  Debug Build:           no
  Trap on FPE (debug):   no
  Check FPE (debug):     no
  UBSan (debug):         no
  Coverage:              no

**************************************************************


-- Configuring done (13.3s)
-- Generating done (0.7s)
-- Build files have been written to: /data/scratch/abc123/fluidsynth-2.4.2/build

All required dependencies for the CMake command have been found and it has run successfully. We can then go on to run the make all install command:

Installing FluidSynth with make all install (click to expand output)
[spack-cmake] $ make all install
[  2%] Creating directories for 'gentables'
[  4%] No download step for 'gentables'
[  6%] No update step for 'gentables'
[  8%] No patch step for 'gentables'
[ 10%] Performing configure step for 'gentables'
-- The C compiler identification is GNU 11.4.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /data/scratch/abc123/fluidsynth-2.4.2/build/src/gentables
[ 13%] Performing build step for 'gentables'
[ 25%] Building C object CMakeFiles/make_tables.dir/make_tables.c.o
[ 50%] Building C object CMakeFiles/make_tables.dir/gen_conv.c.o
[ 75%] Building C object CMakeFiles/make_tables.dir/gen_rvoice_dsp.c.o
[100%] Linking C executable make_tables.exe
[100%] Built target make_tables
[ 15%] Performing install step for 'gentables'
[ 17%] Completed 'gentables'
[ 17%] Built target gentables
[ 19%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/drivers/fluid_aufile.c.o
[ 21%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/drivers/fluid_oss.c.o
[ 23%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_conv.c.o
[ 26%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_hash.c.o
[ 28%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_list.c.o
[ 30%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_ringbuffer.c.o
[ 32%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_settings.c.o
[ 32%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/utils/fluid_sys.c.o
[ 34%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/sfloader/fluid_defsfont.c.o
[ 36%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/sfloader/fluid_sfont.c.o
[ 39%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/sfloader/fluid_sffile.c.o
[ 41%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/sfloader/fluid_samplecache.c.o
[ 43%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_adsr_env.c.o
[ 45%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_chorus.c.o
[ 47%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_iir_filter.c.o
[ 50%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_lfo.c.o
[ 50%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_rvoice.c.o
[ 52%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_rvoice_dsp.c.o
[ 54%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_rvoice_event.c.o
[ 56%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_rvoice_mixer.c.o
[ 58%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/rvoice/fluid_rev.c.o
[ 60%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_chan.c.o
[ 63%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_event.c.o
[ 65%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_gen.c.o
[ 67%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_mod.c.o
[ 67%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_synth.c.o
[ 69%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_synth_monopoly.c.o
[ 71%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_tuning.c.o
[ 73%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/synth/fluid_voice.c.o
[ 76%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_midi.c.o
/data/scratch/abc123/fluidsynth-2.4.2/src/midi/fluid_midi.c: In function 'fluid_player_set_bpm':
/data/scratch/abc123/fluidsynth-2.4.2/src/midi/fluid_midi.c:2575:5: warning: 'fluid_player_set_midi_tempo' is deprecated [-Wdeprecated-declarations]
 2575 |     return fluid_player_set_midi_tempo(player, 60000000L / bpm);
      |     ^~~~~~
/data/scratch/abc123/fluidsynth-2.4.2/src/midi/fluid_midi.c:2552:5: note: declared here
 2552 | int fluid_player_set_midi_tempo(fluid_player_t *player, int tempo)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 78%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_midi_router.c.o
[ 80%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_seqbind.c.o
[ 82%] Building CXX object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_seqbind_notes.cpp.o
[ 82%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_seq.c.o
[ 84%] Building CXX object src/CMakeFiles/libfluidsynth-OBJ.dir/midi/fluid_seq_queue.cpp.o
[ 86%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/drivers/fluid_adriver.c.o
[ 89%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/drivers/fluid_mdriver.c.o
[ 91%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/bindings/fluid_cmd.c.o
[ 93%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/bindings/fluid_filerenderer.c.o
[ 95%] Building C object src/CMakeFiles/libfluidsynth-OBJ.dir/bindings/fluid_ladspa.c.o
[ 95%] Built target libfluidsynth-OBJ
[ 95%] Linking CXX shared library libfluidsynth.so
[ 95%] Built target libfluidsynth
[ 97%] Building C object src/CMakeFiles/fluidsynth.dir/fluidsynth.c.o
[100%] Linking C executable fluidsynth
[100%] Built target fluidsynth
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/pkgconfig/fluidsynth.pc
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/cmake/fluidsynth/FluidSynthConfig.cmake
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/cmake/fluidsynth/FluidSynthConfigVersion.cmake
-- Installing: /data/scratch/abc123/fluidsynth-install/bin/fluidsynth
-- Set runtime path of "/data/scratch/abc123/fluidsynth-install/bin/fluidsynth" to ""
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/libfluidsynth.so.3.3.2
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/libfluidsynth.so.3
-- Set runtime path of "/data/scratch/abc123/fluidsynth-install/lib64/libfluidsynth.so.3.3.2" to ""
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/libfluidsynth.so
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/audio.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/event.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/gen.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/ladspa.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/log.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/midi.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/misc.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/mod.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/seq.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/seqbind.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/settings.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/sfont.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/shell.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/synth.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/types.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/voice.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth/version.h
-- Installing: /data/scratch/abc123/fluidsynth-install/include/fluidsynth.h
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/cmake/fluidsynth/FluidSynthTargets.cmake
-- Installing: /data/scratch/abc123/fluidsynth-install/lib64/cmake/fluidsynth/FluidSynthTargets-relwithdebinfo.cmake
-- Installing: /data/scratch/abc123/fluidsynth-install/share/man/man1/fluidsynth.1

However, if you copied the spack.yaml file from earlier in this tutorial, executing the compiled fluidsynth binary via its full path will fail:

Executing FluidSynth binary
[spack-cmake] $ /data/scratch/${USER}/fluidsynth-install/bin/fluidsynth --version
/data/scratch/abc123/fluidsynth-install/bin/fluidsynth: error while loading shared libraries: libfluidsynth.so.3: cannot open shared object file: No such file or directory

This shared library is present in the lib64 directory of the CMake install prefix:

$ ls -lah /data/scratch/abc123/fluidsynth-install/lib64/libfluidsynth.so.3
lrwxrwxrwx 1 abc123 users /data/scratch/aax286/fluidsynth-install/lib64/libfluidsynth.so.3 -> libfluidsynth.so.3.3.2

Whilst we could manually run some environment exports for $PATH, $LD_LIBRARY_PATH etc. pointing at the relevant directories within /data/scratch/${USER}/fluidsynth-install, there is a more elegant approach.

Adding CMAKE_INSTALL_PREFIX to spack.yaml

The spack.yaml file from GitHub has these edits already

If you used spack-cmake.yaml from the GitHub repository then the edits below are already in place.

You can add the CMAKE_INSTALL_PREFIX you used for FluidSynth (/data/scratch/${USER}/fluidsynth-install in the above example) to your spack.yaml file's prefix_inspections.

First deactivate the Spack environment:

spack env deactivate

List the sub-directories inside the fluidsynth-install directory:

Listing contents of FluidSynth CMake install prefix
$ ls -1 /data/scratch/${USER}/fluidsynth-install
bin
include
lib64
share

Edit the prefix_inspections section of /data/scratch/${USER}/spack-environments/spack-cmake/spack.yaml to add the bin directory from the FluidSynth install prefix to $PATH, the lib64 directory to $LD_LIBRARY_PATH and $LIBRARY_PATH and the include directory to $C_INCLUDE_PATH and CPLUS_INCLUDE_PATH:

Edited spack.yaml with CMake prefix (click to expand)
prefix_inspections:
  /data/scratch/${USER}/fluidsynth-install/bin:
  - PATH
  ./share/aclocal:
  - ACLOCAL_PATH
  ./lib:
  - LD_LIBRARY_PATH
  - LIBRARY_PATH
  ./lib64:
  - LD_LIBRARY_PATH
  - LIBRARY_PATH
  /data/scratch/${USER}/fluidsynth-install/lib64:
  - LD_LIBRARY_PATH
  - LIBRARY_PATH
  ./include:
  - C_INCLUDE_PATH
  - CPLUS_INCLUDE_PATH
  /data/scratch/${USER}/fluidsynth-install/include:
  - C_INCLUDE_PATH
  - CPLUS_INCLUDE_PATH

Then, activate the environment again:

$ spack env activate -p /data/scratch/${USER}/spack-environments/spack-cmake
[spack-cmake] $

Check those environment variables now apply:

Edited Spack environment environment variables
[spack-cmake] $ env | grep PATH=
PKG_CONFIG_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib/pkgconfig:/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib64/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig:/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/share/pkgconfig:.
MANPATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/share/man:/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/man:(etc.)
CMAKE_PREFIX_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view:.
CPLUS_INCLUDE_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/include:/data/scratch/aax286/fluidsynth-install/include:.
ACLOCAL_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/share/aclocal:/usr/share/aclocal:.
LIBRARY_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib:/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib64:/data/scratch/aax286/fluidsynth-install/lib64:.
LD_LIBRARY_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib:/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/lib64:/data/scratch/aax286/fluidsynth-install/lib64:.
PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/bin:/data/scratch/aax286/fluidsynth-install/bin:(etc.)
C_INCLUDE_PATH=/data/scratch/aax286/spack-environments/spack-cmake/.spack-env/view/include:/data/scratch/aax286/fluidsynth-install/include:.

And your compiled application FluidSynth should now be available and run successfully:

Running FluidSynth
[spack-cmake] $ which fluidsynth
/data/scratch/abc123/fluidsynth-install/bin/fluidsynth
[spack-cmake] $ fluidsynth --version
FluidSynth runtime version 2.4.2
Copyright (C) 2000-2024 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.

FluidSynth executable version 2.4.2
Sample type=double

In a job script or interactive job

Now that your environment is created, you can activate it and use it in a job script or interactive job with the following lines:

module load spack/<version>
spack env activate /data/scratch/${USER}/spack-environments/spack-cmake
fluidsynth <command>

The -p flag is not required in job scripts because the decorated prompt will not be observed within non-interactive jobs. The fluidsynth binary will be available as long as you activate your Spack environment as part of the job script or during the interactive job.