测试动态库函数是否存在:

 1 #include <stdio.h>
 2 #include <dlfcn.h>
 3 
 4 int main(void)
 5 {
 6     void *soHandle = dlopen("*.so", RTLD_LAZY);
 7     if (!soHandle)
 8     {
 9         printf("%s\n", dlerror());
10         return -1;
11     }
12     void *fun = dlsym(soHandle, "avio_test");
13     if (!fun)
14     {
15         printf("fun == NULL\n");
16     }
17     if (soHandle)
18         dlclose(soHandle);
19 
20     return 0;
21 }

================================================================================================

动态库函数全局化和私有化:

第一种方式:

1     #define FOX_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))   
2     #define FOX_HELPER_DLL_LOCAL  __attribute__ ((visibility("hidden"))) 

第二种方式:

gcc 在链接时设置 -fvisibility=hidden,则不加 visibility声明的都默认为hidden; gcc默认设置 -fvisibility=default,即全部可见

第三种方式:

使用export map,gcc -Wl,--version-script=export.map, 在export.map中指定

1 {
2 
3 global:export_func;
4 
5 local:*;
6 
7 };

参考:

1.http://blog.csdn.net/zdragon2002/article/details/6061962

2.http://blog.csdn.net/zhongyunde/article/details/5939733

 

posted on 2013-03-25 18:31  孜求嵌道  阅读(309)  评论(0编辑  收藏  举报