天天看点

linux直接运行so示例

#include <unistd.h> 
  
const char banner[] = "linux直接运行so示例 run so  demo \n Hello World\n"; 
  
extern int main (void) __attribute__ ((noreturn)); 
int main() 
{ 
         __write (STDOUT_FILENO, banner, sizeof banner - 1); 
         _exit(0); 
} 

//gcc -shared -fPIC -fpic -o run_so.so run_so.c -Wl,-emain 
// linux32运行  /lib/ld-linux.so.2 ./run_so.so 
// linux64运行 /lib64/ld-linux-x86-64.so.2 ./run_so.so