[英]calling shared object crashes at the second time
I have created a ".so" file and invoked from my code. 我创建了一个“ .so”文件,并从我的代码中调用了该文件。 It works very well for the first time, and I am getting the desired result, whereas when the same so is invoked for the second time its getting crashed. 第一次效果很好,我得到了预期的结果,而第二次调用相同的结果时,它崩溃了。 The below is my code. 下面是我的代码。 Am I doing anything wrong. 我做错什么了吗?
#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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.