Linking main from within a library.

Linking main from within a library.

Post by Erik Schmid » Fri, 04 Jul 2003 14:45:47



Hello all,

I'm having a problem linking a bunch of library files if on of the library
files contains main().  It's like the linker can't find my main() and is
instead substituting in an empty main() (and __main() ).

I'm using the m68k-coff-gcc/ar tools created by David Fiddes.

Lets say that I have the two library files: libx.a and liby.a.  libx.a
contains functions named main() and __main() (as well as other functions).
liby.a contains other misc. functions that have first be compiled from .c
files to .o files.

When I do "m68k-coff-gcc -m5200 -T<mylinkscript.ld> -Wall -nostdlib libx.a
liby.a"  The a.out file simply contains two empty versions of main() and
__main() and doesn't import any of the other supporting functions out of the
libraries.

Assuming that main.c contains my main/__main functions, if I do
"m68k-coff-gcc -m5200 -T<mylinkscript.ld> -Wall -nostdlib main.c libx.a
liby.a" then the main functions are seen and everything is compiled fine.
The proper functions from the libraries are all included in the output.

I think that everything should be trying to link statically...how can I be
sure of this?

Any ideas?

Cheers,
Erik