Shared library data share


Hi, now a days i research for shared library.

i know audio plugin is shared library.

so i make 2 plugins, and 1 shared library(not audio)

so i shared data(variable int, float, array) between plugin using shared library.

i realize plugin1, 2 has different value.

if plugin 1 write (a =3)
then plugin 2 read a =0 ( i think ‘a’ in plugin2 has different memory address)

so any compile option(link option, such as symbol) is exist help me??


It depends on how you load the shared library. You probably want to use the dlopen command directly with the RTLD_GLOBAL flag. The default is that every plug-in which loads the shared library will have it’s own private copy.


thank you for your reply!
Actually, I also research before.
my plugins are opened by DAW(dopen dynamicallay), but my shared library is opened at first.

so in this case, i also adjust RTLD_GLOBAL? this means i give option at first.


Well it’s loading it before as you’ve linked your plug-in to the shared lib. Then you have no control over RTLD_GLOBAL. You need to not link you plug-in to the shared lib and resolve all symbols at run-time. This might be quite difficult to do. IMHO if you have no good reason to be loading a shared lib in your plug-in then you should probably avoid it. It can cause all sort of problems. For JUCE 4.1, we also put some of the JUCE code in a shared library. A storm of complaints and bugs came in via the forum so we reverted that change only a day later.


Thank you fabian.
and your experience about shared library in JUCE 4.1. (it is amazing)

so, shared memory (ipc, despite of same process) is the right access? (i also try - it works well)

ps. juce is amazing and i learn many things about audio programming and c++. thank you again.


Technically you could just use global variables as most hosts will only ever load your shared library once and then simply create several instances of your plug-in. Therefore, there will only be a single instance of your globals regardless of the number of plug-in instances loaded.

However, I personally would not rely on this behaviour. Some DAWs may sandbox plug-ins in the future and break your plug-in. I’d rather rely on IPC.