How to add a JUCE-built static library into another Projucer project?

Working with Mac OS X and Xcode, JUCE 5.4.7.

I have a GUI app and plugin projects that refer to some common code, so I wanted to put the common code into a static library.

I created a new static library project in Projucer, added the source code, opened it in Xcode, and built the library. OK, great, now I have something called MyLibrary.a.

How and where do I add this into my other Projucer Projects where I want to incorporate it and replace the common code?

I would advise to create a JUCE module instead, if its just for code re-usability.

If you do really need to create a static library:

There are sections in the Projucer Exporters for adding libraries to a project, External Libraries to Link and Library/Header Search Paths:

You can also add an Xcode subproject for Mac/iOS projects which is a nice way to work if you do need a separate library for distributing, as you can develop the library alongside the app that uses it.

Thanks for that info. I’d like to look into the module option, but is there any good reference on how to create a JUCE module? I’m not finding much so far…

JUCE modules are really just a big “.h” file including your other header files, and a “.cpp” file including your source files, along with some metadata that helps the projucer parse it for different projects.

Have a look at one of the simpler JUCE provided modules, like juce_osc to get started - it’s quite simple to copy/paste to a new location, add your own sources/metadata and add to the projucer.

The main thing to note when porting existing code to a JUCE module is that all the code in a module will share the same translation unit, so you probably want to remove all #include statements from them (especially JuceHeader.h), and look out for other things (const variable names, for example) that might cause name conflicts.

If it can be of any help, in the past I have written some notes to myself on how to structure a JUCE module, based on some guesswork in addition to what’s written in the official JUCE Module Format.txt which is found in JUCE codebase:

(disclaimer: this was written a few years ago and some details may have changed a little, especially with the introduction of JUCE 6, but the overall description is still valid IMHO)


Also you can check some examples of modules here:

1 Like