* removal of unreferenced static variables
@ 2003-04-01 15:30 Simon MORLAT
2003-04-02 14:35 ` Matthias Oltmanns
0 siblings, 1 reply; 2+ messages in thread
From: Simon MORLAT @ 2003-04-01 15:30 UTC (permalink / raw)
To: gcc-help
Hello all,
Is there an option to prevent gcc to skip out of a program unreferenced
static objects ?
I've looked at the manual but found nothing that worked.
Here is my practical example (stupid here, but simplified from a real
case):
in object1.h
class Object1
{
public:
Object1(){
std::cout<<"Object 1 is living"<<endl;
}
}
in object2.h:
#include "object1.h"
class Object2
{
public:
void fantasticFunction(){
cout<<"does nothing interesting.";
}
private:
static Object1 _myobject1;
}
in object2.cc
#include "object2.h"
Object1 Object2::_myobject1;
Now let's say that object2.o is part of library called libobjects[.a or
.so]
*When I link my main program with libojects.so (shared lib), then I can
see "Object1 is living" before entering main. It shows that _myobject1
has been initialized.
*When I link my main program with libobject.a (static lib), then the
behaviour is a bit different:
- if the program references an Object2 class, then _myobject1 is
correctly initialized.
- if the program does not reference any symbol related to Object2, then
_myobject1 is not initialized, I can't seen "Object1 is living."
This is very problematic for me. Some other C++ compilers offer ways to
workaround this, but I did not find anything for g++.
I tried to change static to "const static", tried -keep-const-static
without effect.
Thank you very much in advance for your help.
--
Simon MORLAT <simon_morlat@hp.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: removal of unreferenced static variables
2003-04-01 15:30 removal of unreferenced static variables Simon MORLAT
@ 2003-04-02 14:35 ` Matthias Oltmanns
0 siblings, 0 replies; 2+ messages in thread
From: Matthias Oltmanns @ 2003-04-02 14:35 UTC (permalink / raw)
To: Simon MORLAT; +Cc: gcc-help
Am Die, 2003-04-01 um 17.26 schrieb Simon MORLAT:
> Hello all,
>
> Is there an option to prevent gcc to skip out of a program unreferenced
> static objects ?
>
hi,
i've got a similiar problem and the the flag
`-u SYMBOL'
worked for me.
from gcc-info:
`-u SYMBOL'
Pretend the symbol SYMBOL is undefined, to force linking of
library modules to define it. You can use `-u' multiple times with
different symbols to force loading of additional library modules.
cu
Matthias
--
Matthias Oltmanns
Tel: 04421-1543-274
mail: Mathias.Oltmanns.Oltmanns@sysde.eads.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-04-02 14:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-01 15:30 removal of unreferenced static variables Simon MORLAT
2003-04-02 14:35 ` Matthias Oltmanns
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).