[linux-audio-dev] Static class data and dlopen()
clemens at ladisch.de
Mon May 19 13:03:01 UTC 2003
Alfons Adriaensen wrote:
> Imagine you have a C++ class S which has some static data.
> Derive A from S and use A to create a plugin a.so
> Derive B from S and use B to create a plugin b.so
> When a host links (at runtime) with both a.so and b.so,
> then the static data from S will be created twice (I verified
> this to be the case).
> This is what I expected, but it may shock C++ purists, ...
The C++ Standard doesn't mention dynamic linking, therefore any result
whatsoever would conform to the standard. (It's "undefined behaviour", so
C++ purists would expect nasal demons ... ;-)
> Is this the 'official' behaviour when loading plugins, or is this
> something that could change with future version of g++ and the DL libs ?
When you linked a.so (and b.so), you told the linker to put the object
file with the definitions of S's static data into the .so file.
It should be possible to have one copy of the static data by storing S's
static data into a common s.so which is linked to by the other two .so's.
More information about the Linux-audio-dev