[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Problems linking lib that uses the constructor __attribute
m0n0 wrote:
It seems gcc is only adding it to ctor if it is already
referenced...
Yes, you are right.
This is because of the rule:
"A .o file located inside a static library will be linked only if some other
previously linked object require it".
However, the .o file contains the special __attribute__((constructor)) to
auto register itself, but only when it is already linked :-(
So the only solution is to force the linkage of the .o file containing the
SDL frontend:
- by adding a reference to any public symbol defined in the file containing
the __attribute__((constructor)). This may be a reference to
sdl_register_frontend() (like you posted in your other message) or a
reference to another public function or variable defined in the same file.
- or :
There is an trick to make it compile correctly: use the
-Wl,--whole-archive flag, but Vincent told me to not use this flag ... :)
I told this should not be used, except in very special cases... like this
one :-)
But his method is inefficient, because it will really include all the
contents of the library into your final executable, including useless .o
files. This will work, but it will also highly increase the size of your
executable.
I don't know a clean solution for this problem.
Your ugly method is probably the best - until someone has a better idea.
--
Vincent Rivière