This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ static object initialization
- To: "Joel W. Reed" <jreed at support dot ddiworld dot com>
- Subject: Re: c++ static object initialization
- From: "Janis Johnson" <janis at us dot ibm dot com>
- Date: Wed, 7 Mar 2001 09:24:04 -0800
- Cc: GCC List <gcc at gcc dot gnu dot org>
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