Using GCC to produce small executables (OSX)

Adrian Boeing aboeing@gmail.com
Sun Feb 14 04:46:00 GMT 2010


Hi,

I am trying to compile a small program with the aim of reducing the
output file size on OSX:

int main(void) {
return 99;
}

I compile with:
gcc tiny.c
and run :
./a.out
echo $?
99

But:
ls -al a.out
Reveals a file of 8664 bytes. (A bit much! Strip reduces this only by
~100 bytes!)

Windows/MSVC does something similar, but if you disable the standard
libraries, you get a executable of 200 or so bytes.

I tried the same with GCC on OSX, but I get:
gcc tiny.c -nostdlib
ld: could not find entry point "start" (perhaps missing crt1.o)
collect2: ld returned 1 exit status

If I try and pass the entry point to LD, I get:
gcc tiny.c -c -nostdlib -m32
ld tiny.o -e main
ld: could not find entry point "main" (perhaps missing crt1.o) for
inferred architecture i386

How can you tell the linker what the entry point function is?
If anyone has any tips on how I can bring the file size down I would
be keen to hear it.

Thanks,
-Adrian



More information about the Gcc-help mailing list