历史经验之Solaris9下创建DLL方法

整理日期: 2008年11月3日
本文简单说明如何在Solaris9下创建动态连接库方法

//dll.c
#include <stdio.h>
int fun1(int a)
{
  printf("api function test\n");
  a = a+10;
  return a+1;
}

生成DLL:
1.gcc -c -fpic dll.c -o dll.o
2.gcc -shared -lc dll.o -o /usr/lib/libmy_dlldll.so
说明:选项 -fpic 和 -fPIC 导致生成的代码是位置无关的,重建共享目标库需要位置无关。-fPIC 选项产生位置无关的代码,这类代码支持大偏移。
店铺地址:https://shop66907778.taobao.com/

//test_dll.c
#include <stdio.h>
extern int fun1(int a);
main()
{
  printf("fun is %d\n", fun1(1));
  return 0;
}

生成执行文件:
gcc -lmy_dll test_dll.c -o test_dll
注意:可以用ldd test_dll查询test_dll符号连接情况

猜你喜欢

转载自blog.csdn.net/weixin_41486034/article/details/106256195
今日推荐