- 论坛徽章:
- 1
|
情况如下:
我自己编写了一个libtest.so,然后写了一个简单的测试程序:- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <dlfcn.h>
- int main()
- {
- printf("-----for test begin-----\n");
- unsigned long int handle = 2;
- void *dp = dlopen("/lib/libtest.so", RTLD_LAZY);
-
- char *pszErr = dlerror();
- if( !dp || pszErr )
- {
- printf("Load libtest.so failed!\n");
- return 1;
- }
- int (*File_Open)(unsigned long int*,int) = dlsym(dp, "File_Open");
- int ret = File_Open(&handle,0);
- printf("ret = %d\n",ret);
- printf("handle = %d\n",handle);
- dlclose(dp);
- printf("-----for test end-----\n");
- return 0;
- }
复制代码 gcc -o test test.c -ldl
生成test可执行文件,下载到目标板后运行,打印-----for test end-----后出现segmentation fault,
注释掉“dlclose(dp);”segmentation fault未出现,个人感觉很奇怪,如果dlclose()调用引起的
segmentation fault那应该不打印-----for test end-----啊,但注释掉就没问题了,搞不懂啊! |
|