How to compile C source code without a main function?
On GCC, the -c
switch is what you want.
-c
means "compile, don't link", and you get a name.o
output file.
Suppose you have hello.c:
#include<stdio.h>
#include<stdlib.h>
_start()
{
exit(my_main());
}
int my_main()
{
printf("Hello");
return 0;
}
Compile as:
gcc -nostartfiles hello.c
and you can get an executable out of it.