How to make another function entry point other than main () in C
2 answers
There is a solution for building an executable shared library where you can build a program using another function as an entry point.
The code looks like this:
#include <stdio.h>
#include <stdlib.h>
const char __invoke_dynamic_linker[] __attribute__ ((section (".interp")))
= "/lib/ld-linux.so.2";
void fun()
{
printf("This is fun./n");
exit(0);
}
Then build your program as a shared library and specify func as the entry point:
$ gcc -fpic -shared -o fun.so -Wl,-e,fun fun.c $ ./fun.so
The problem with this method is that func cannot have normal arguments like we have in the main function, this is because we don't have a c library to initialize the main arguments.
-1
source to share