On Thu, Apr 15, 2010 at 10:59 PM, Torsten Dreyer <tors...@t3r.de> wrote:

> Hi,
>
> this is a question for the gnu linker geek:
>
> I am trying to add gnucap to FlightGear as posted before. It compiles
> cleanly
> and links fine, but there is one issue. Gnucap uses commands which are
> implemented in separate files. These commands get registered into a global
> command registry. Here is a code snipped for the "clear" command:
>
> class CMD_CLEAR : public CMD {
> public:
>  void do_it(CS&, CARD_LIST* Scope)  {
> // .. do something fancy here
>  }
> } p0;
> DISPATCHER<CMD>::INSTALL d0(&command_dispatcher, "clear", &p0);
>
> The class CMD_CLEAR implements the CMD interface which requires the do_it()
> function.
> The DISPATCHER template contains a INSTALL class, it's constructor performs
> the registration into the registry. In theory, when the INSTALL class is
> instantiated as d0, the actions in the constructor are performed.
> Unfortunately, this does not happen when linked against FlightGear.
> I tried to rename d0 into something more uniqe and grep'ed the created
> object
> and library for the variable which were found there, but not in the fgfs
> executable. This lead me to the conclusion, that the linker optimizes the
> unused variable from the executable.
>
It's not optimizing the variable, it's optimizing the entire .o file out of
the linkage, as nothing external is explicitly using any of the symbols in
the .o. This is a major weakness of the registration pattern when statically
linking.

>
> Is there any magic switch to pass to the g++ linker telling him not to
> optimize unused variables, preferably for a certain set of files or a
> single
> library?
>
No. Either build gnucap as a shared library or add some dummy references to
symbols in the file(s) that are referenced, perhaps indirectly, by code
outside of the library.

Tim
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to