现在的位置: 首页 > 综合 > 正文

Linux 动态库链接和调用

2014年03月05日 ⁄ 综合 ⁄ 共 303字 ⁄ 字号 评论关闭

1. 编写Shared Object(共享对象,或动态库)文件

#include <stdio.h>

myLibFunction(){ 

printf("myLibFunction called.\n")

}

保存为so.so

2. 编译动态库文件

gcc so.c -fPIC -shared -o libso.so

3. 编写测试文件

int main(){

myLibFunction();

return 0;

}

保存为test.c

4. 编译测试文件

gcc test.c -L. -lso -o test

5. 将动态库地址添加到/etc/ld.so.conf文件中

参考:http://www.linuxidc.com/Linux/2011-10/45744.htm

抱歉!评论已关闭.