【发布时间】:2013-11-26 16:18:43
【问题描述】:
我创建了一个“.so”文件并从我的代码中调用。它第一次运行得很好,我得到了想要的结果,而当第二次调用相同的 so 时,它就会崩溃。以下是我的代码。我是不是做错了什么。
#include <dlfcn.h>
#include <stdio.h> /*for printf() */
#include <stdlib.h> /* for exit() */
#include <FaceRecognition.h>
#include <string>
using namespace std;
typedef void (*pf)( string, string, string );
int func ()
{
void *lib;
pf greet;
const char * err;
lib=dlopen("/home/libh.so", RTLD_NOW);
if (!lib)
{
printf("failed to open hello.so: %s \n", dlerror());
exit(1);
}
dlerror(); /*first clear any previous error; redundant
in this case but a useful habit*/
greet= (pf) dlsym(lib, "sample");/*locate hello() */
err=dlerror();/*check for errors and copy error message*/
if (err)
{
printf("failed to locate hello(): %s \n", err);
exit(1);
}
greet( "auth", "/home", "/home/train1.gal" ); /*call hello() */
dlclose(lib);
return 0;
}
int main () {
func(); --> getting the expected result for the first time
func(); --> getting crashed here ( core dumbed)
}
【问题讨论】:
-
可能是dll没有正确卸载
-
@Paranaix 如何卸载它? dlclose 不会这样做吗?
-
我的意思是 dll 代码本身有问题,如果卸载了也不会正确取消初始化,这只是猜测
-
使用
-g3 -o0编译所有内容并使用调试器。
标签: c++ c dll shared-libraries