Importing third party libraries in a Juce project

First of all you have to distinguish between three concepts:

  • Header Only Libraries: Those libraries are included in your compilation unit (aka .cpp file) and get compiled along with the compilation unit they are included in
  • Libraries to compile along with your project: This is the concept of the JUCE module format (just have a look in the Modules tab on the left of your Projucer window – there you see the Modules your project uses). This kind of libraries have one or more own compilation units which get compiled along with the other compilation units your project consists of. This is much like just adding a .cpp file directly to your project.
  • Precompiled libraries: Those libraries are either really complex to build or closed source. You only get a precompiled version of them and a header file describing their interface. You need to tell the linker that it should include the precompiled library in the linking step – therefore you’ll find the External Libraries To Link field in every Exporter for your Projucer project.

For both, header only libraries and precompiled libraries the compiler needs to know the directories where it should look for the header file. If this directory is relative to the current source file, you can chose the #include "foo/bar.h" syntax, this includes the header bar.h in the directory foo that is expected to be placed next to your current source file. To become independent of this relation you can pass one or more folders where the compiler should look for header files. If you click the little gear icon on the top left of your Projucer window, you’ll find the field Header Search Paths where you can put in directories where the compiler should look for headers. To include a file from the header search path you use the #include <foo/bar.h> syntax.

So TLDR: As the library you want to use is a header only library just add the directory of it to your project’s header search path :wink: Because this is the easiest way to include a library, many people like header only libraries.

4 Likes