This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++ static object initialization



Joel W. Reed wrote:

> i have two .so files each with a static object that is named
> the same. this seems to confuse gcc/ld/something as one .so
> file is incorrectly using the object from the other .so file.
>
> this problem went away if i put one of the objects in one
> of the .so files in its own separate namespace.
>
> is this a known problem? am i just doing something wrong?
> have i explained this well enough...

The behavior depends on your linker and dynamic linker and is very
non-portable.  Even if the dynamic linker resolves all references to the
same object, the constructors and destructors for both objects might be
called, leading to very confusing problems.

Putting one of the objects into a separate namespace makes the linkers
see it as a separate entity, just as if it had an entirely different
name.

Janis


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]