我创建了一个“.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)
}
答案 0 :(得分:0)