My software has one main for normal use and a different one for unit tests. I would just love it if there was an option to gcc to specify which "main" function to use.
The other answers here are quite reasonable, but strictly speaking the problem you have is not really one with GCC, but rather with the C runtime. You can specify an entry point to your program using the -e
flag to ld
. My documentation says:
-e symbol_name
Specifies the entry point of a main executable. By default the entry name is "start" which is found in crt1.o which contains the glue code need to set up and call main().
That means you can override the entry point if you like, but you may not want to do that for a C program you intend to run normally on your machine, since start
might do all kinds of OS specific stuff that's required before your program runs. If you can implement your own start
, you could do what you want.