Building shared lib?

I’m trying to create a shared lib using CMake, but whenever I add something like this:

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES_ENGINE} ${SOURCE_FILES_UI})

I get this kind of error:

CMake Error at JUCE/extras/Build/CMake/JUCEUtils.cmake:470 (message):
  Target AudioEngine does not have a generated sources directory.  Ensure
  it was created with a juce_add_* function
Call Stack (most recent call first):
  CMakeLists.txt:112 (juce_generate_juce_header)

I’ve tried removing the source_group stuff based on some comments I read in the API, but still no joy. The full CMakeLists.txt is pretty long, but I can prepare a barebones example if it’s not immediately clear what the problem is :+1:

You can only generate a juce header for a target added with one of the juce_add_ functions. It sounds like you’re trying to add a juce header for the library target, but that is not currently supported.

So it’s not possible to create a JUCE-based library, or at least not using CMake or the Projucer?

You can just include the JUCE module headers directly, instead of using a JUCE header file.

Using JUCE from a library is maybe not recommended - JUCE doesn’t have a stable ABI, so you probably shouldn’t expose any JUCE types/functions from your library, unless you’re prepared to rebuild everything that depends on your library every time the library/JUCE changes.

Right got yeah. I don’t plan on exposing much of JUCE. I’m just going to use a single parameter called awesome that can be cranked up to 11 :laughing:

Just a follow up on this to say I have been able to get my library building and working fine. Just one issue though. If I include the library code as part of a test app, I get no leaks on exit. But as soon as I load and unload the static libs I get hit with an abundance of the the following(see below). And that’s only a short selection of the leaks.

Is there anything I should be watching out for in particular here? Tips or advice on how to avoid such leaks would be most welcome.

***** Leaked objects detected: 9 instance(s) of class RenderingOp**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
***** Leaked objects detected: 9 instance(s) of class RenderingOp**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
***** Leaked objects detected: 1 instance(s) of class OwnedArray**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
***** Leaked objects detected: 1 instance(s) of class OwnedArray**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
***** Leaked objects detected: 2 instance(s) of class AudioBuffer**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
***** Leaked objects detected: 4 instance(s) of class MidiBuffer**
**JUCE Assertion failure in juce_LeakedObjectDetector.h:92**
etc....

Yet another message to myself :laughing: So it’s all good now. The library destructor wasn’t being called if I simply closed the host. Armed with that knowledge it was pretty simply to fix those leaks. :+1: