Re: [linux-audio-dev] Static class data and dlopen()

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Static class data and dlopen()
From: Clemens Ladisch (clemens_AT_ladisch.de)
Date: Mon May 19 2003 - 19:50:50 EEST


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.

HTH
Clemens


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Mon May 19 2003 - 20:11:21 EEST