🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3390

Re: C++ globals and shared lib, how to ?

#3390
From: mgogala
Date: Wed, 03 Feb 1999 00:00
41 lines
2263 bytes
In article <36B5EA0E.2361@imag.fr>,
  Yves Dufournaud <Yves.Dufournaud@imag.fr> wrote:
> Hi,
>
> I'am trying basic things using dlopen with g++-2.7.2.3 on sunos 5.5 :
>
> I'am loading a file dynamic.o using dlopen
> this file is c++ with global object inside.
>
> I've compiled it using
> g++ -shared dynamic.cc -export-dynamic
>
> but when I load it with a dlopen and using RTLD_NOW
> constructor of global object are not called.
>
> I don't understand why (my version of g++ generate elf) ?
>
> please help,
>
> thanks,
>
> Yves.
>
> --
> Yves Dufournaud Email Yves.Dufournaud at imag.fr equipe MOVI laboratoire
> GRAVIR
> --
>
Constructors for global objects are called from global initialization routine
typically caled crtbegin.o, which is linked into the ELF file when it
contains function "main". If you use dlsym and dlopen, to invoke the
routine, your program will not call constructors for the global objects in
that shared object. The only way to initialize global objects specified in
the shared library is to invoke some kind of explicit creation routine and
initialize them manually. That means to include routine named "InitMyGlobals"
in the shared library and then use dlopen to open it and then dlsym to get
the symbol you are looking for.
Mladen Gogala

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
Technical Details
Message-ID: <798act$a7i$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36B5EA0E.2361@imag.fr>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc89c,3b56ba1236b2e4f
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 10ba33,3b56ba1236b2e4f
X-Google-Attributes: gid10ba33,public
X-Google-Thread: 11035d,3b56ba1236b2e4f
X-Google-Attributes: gid11035d,public
From: mgogala@yahoo.com
Subject: Re: C++ globals and shared lib, how to ?
Date: 1999/02/03
Message-ID: <798act$a7i$1@nnrp1.dejanews.com>
X-Deja-AN: 439994853
References: <36B5EA0E.2361@imag.fr>
X-Http-Proxy: 1.0 x10.dejanews.com:80 (Squid/1.1.22) for client 38.26.95.219
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Wed Feb 03 01:56:50 1999 GMT
Newsgroups: comp.unix.programmer,comp.unix.solaris,gnu.g++.help
X-Http-User-Agent: Mozilla/4.5 [en] (X11; I; SunOS 5.6 i86pc)