This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc/ld init section and libraries
- From: "John Donoghue" <john dot donoghue at ieee dot org>
- To: John Love-Jensen <eljay at adobe dot com>
- Cc: John Donoghue <john dot donoghue at ieee dot org>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Sat, 12 Aug 2006 00:47:30 +0930
- Subject: Re: gcc/ld init section and libraries
- References: <C101E9CD.14405%eljay@adobe.com>
I fixed the problem now I think:
I had an init.c that held the initialization code init. Which wouldnt have
been included in the link as the init function and section hook wasnt being
referenced.
When I put the init function in a file with functions that will be used, the
init function gets included.
Easy now that I know :)
John Love-Jensen writes:
Hi John,
The linker only pulls out .o from the .a that fulfill currently known
(single pass) missing symbols.
The linker also takes any .o in its entirety, it doesn't check for missing
symbols.
With the GNU linker, there is the -whole-archive switch. So if you want
libfoo.a wholesale, but libbar.a and libquux.a to only be used to fulfill
missing symbols, do something like this:
gcc -o myapp alpha.c beta.c gamma.o delta.o -L. -Wl,-whole-archive -lfoo
-Wl,-no-whole-archive -lbar -lquux
Because the linker perfoms a single pass for resolution of missing symbols
in libraries (.so, or .a), order is very important. And if you had an
interdependency (ick ick! avoid avoid!) between, say, bar and quux, you may
need to do something distasteful like -lbar -lquux -lbar.
HTH,
--Eljay