* =====================================================================================
*
asdfasdfasdf* Filename: f.c
*
* Description:
*
* Version: 1.0
* Created: 2013年12月20日 14时31分47秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include "l.h"
__attribute__((constructor)) void before_main()
{
printf("constructo rbefore main\n");
}
__attribute__((destructor)) void after_main()
{
printf("destructor after main\n");
}
int main()
{
pp();
printf("in main\n");
return 0;
}
#######################################分割符号###############################################
/*
* =====================================================================================
*
* Filename: l.c
*
* Description:
*
* Version: 1.0
* Created: 2013年12月20日 14时55分40秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include "l.h"
void _init(void)
{
printf("%s\n", __func__);
}
void _fini(void)
{
printf("%s\n", __func__);
}
void pp(void)
{
puts("xxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
}
#######################################分割符号###############################################
/*
* =====================================================================================
*
* Filename: l.h
*
* Description:
*
* Version: 1.0
* Created: 2013年12月20日 14时55分40秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
void pp(void);
#######################################分割符号###############################################
gcc -shared -fPIC l.c -nostartfiles -o libl.so //-nostdlib也是可以的
sudo cp libl.so /usr/lib
gcc f.c libl.so