help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: constructors not called in dynamic object, Linux only.


From: Paul Pluzhnikov
Subject: Re: constructors not called in dynamic object, Linux only.
Date: 02 Feb 2005 13:14:18 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence)

James Kanze <kanze@none> writes:

> Anyway, the problem seems clear; something isn't getting linked
> correctly into the main, so dlopen isn't finding it.

Correct. And it has nothing to with constructors.
The fix:

 g++ -g -fPIC -o ./test IF.o main.o -ldl -rdynamic

After the fix:
$ ./test Test1
Loading Test1
Loading Test1
IF: ctor for test1
Test1 loaded
Test1 not loaded

> I don't know why it works
> under Solaris, and not under Linux; maybe the different linkers?

Yes: from 'info ld' (gcc translates '-rdynamic' into '-export-dynamic'):

`-E'
`--export-dynamic'
     When creating a dynamically linked executable, add all symbols to
     the dynamic symbol table.  The dynamic symbol table is the set of
     symbols which are visible from dynamic objects at run time.

     If you do not use this option, the dynamic symbol table will
     normally contain only those symbols which are referenced by some
     dynamic object mentioned in the link.

     If you use `dlopen' to load a dynamic object which needs to refer
     back to the symbols defined by the program, rather than some other
     dynamic object, then you will probably need to use this option when
     linking the program itself.


> This seems pretty basic; I feel sure that there's just an option
> or something that I've missed.

Correct :)

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]