您的位置:首页 > 运维架构 > Linux

How to write/use DLL in Linux sy…

2014-01-15 12:06 537 查看
1. How to use DLL to create c++ class
http://blog.csdn.net/tlzhu/archive/2008/07/17/2663777.aspx2. How to write DLL and use DLL
http://www.ibm.com/developerworks/cn/linux/sdk/dll/index.html3. 在linux下编写动态链接库的步骤
http://blog.chinaunix.net/u3/97568/showart_2046606.htmldlopen -- load dll file to memory
dlerror -- return load failure root cause
dlsym - load function pointer from certain
dll in memory
dlclose - release dll file from memory4. A very simple case
http://bbs.loveunix.net/viewthread.php?tid=24316而在linux下 没有那么麻烦 下面给出例子
//dll.c mushuang 2004/03/24

#include <stdio.h>

void print_dll()

{

   printf(" call dll
success\n");

}

CODE

//call.c mushuang 2004/03/24

extern void print_dll();

int main()

{

   print_dll();

   return 0;

}

CODE

all:libdll.so call

libdll.so:dll.c

$(CC) -fPIC -shared -o $@ $<

call:call.c

$(CC) -L. -ldll call.c -o call

运行

LD_LIBRARY_PATH=. ./call

在linux下 不需要特别的修饰符 同样 编译动态库时 也不会生成静态库用于导入

在链接时 直接与动态库连接 十分简单

动态库只要使用-fPIC -shared就可以了
fPIC告诉编译器生成与位置无关代码 

-shared表示生成动态库

后面的执行 

因为默认的动态库查找路径不包括当前目录 所以使用LD_LIBRARY_PATH告诉shell到当前目录下查找库

很简单 不是吗

[code]


  

 

 

 

 

 

 

 

 

  

  

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐