Skip to content

Instantly share code, notes, and snippets.

@liyang85105
Last active August 14, 2017 05:59
Show Gist options
  • Save liyang85105/58ca8e74115041ad8add9b41720597ad to your computer and use it in GitHub Desktop.
Save liyang85105/58ca8e74115041ad8add9b41720597ad to your computer and use it in GitHub Desktop.
specify entry point of a c/c++ program instead of main
#include <stdio.h>
#include <stdlib.h>
/*extern "C"*/ int sum(int a, int b)
{
return 2 * a + 3 * b;
}
/*extern "C"*/ int entry()
{
printf("this is call from function test\n");
printf("result of sum(1,2) = %d\n", sum(1,2));
exit(0);
}
//int main()
//{
// printf("this is call from function main\n");
// return 0;
//}
// compile command
// gcc -fPIE -nostartfiles no_main.c -Wl,-eentry -o no_main
or
// gcc -fPIE -nostartfiles -e entry no_main.c -o no_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment