如何在Linux上使用LoadLibrary()?高手请教!

在MS的WINDOWS系统中有一个LoadLibrary()函数可以在程序运行时加载DLL,在Linux中有类似的功能么?高手请教!
---------------------------------------------------------------

dlopen
参见:
http://expert.csdn.net/Expert/topic/1385/1385737.xml?temp=.8568994
sharelib.c

#include

 1<stdio.h>   
 2  
 3void print()   
 4{   
 5extern int a;   
 6fprintf(stdout,"Hello, World, I'm ari, %d\n", a);   
 7}   
 8  
 9main.c   
10===================   
11#include <dlfcn.h>   
12#include <stdio.h>   
13  
14int a;   
15int main()   
16{   
17void *dp;   
18char *error;   
19void (*errmsg)(void);   
20a = 2;   
21dp = dlopen("./mylib.so", RTLD_LAZY );   
22if( dp ==NULL ){   
23printf("%s\n", dlerror());   
24exit(1);   
25}   
26errmsg = dlsym(dp, "print");   
27errmsg();   
28error = dlerror();   
29if( error )   
30printf("%s\n",error);   
31dlclose(dp);   
32return 0;   
33}   
34  
35Makefile   
36====================   
37mylib.so:   
38gcc -shared -o mylib.so sharelib.c   
39  
40main:   
41# make global for all   
42gcc -rdynamic -o main main.c -ldl   
43# make global notfor all   
44#gcc -o main main.c -ldl</stdio.h></dlfcn.h></stdio.h>
Published At
Categories with 服务器类
Tagged with
comments powered by Disqus