动态库调用的问题
好梦一场睡 2013-08-06 10:38:18 这是man.cpp
#include<iostream>
#include<dlfcn.h>
using namespace std;
int main()
{
void *handle=dlopen("./libprint.so",RTLD_LAZY);
typedef void(*haha)();
if(!handle)
{
cout<<"dlopen error"<<endl;
return 1;
}
haha lprint=(haha)dlsym(handle,"lprint");
const char *error=dlerror();
if(error)
{
cout<<"dlsym error"<<endl;
dlclose(handle);
return 1;
}
lprint();
dlclose(handle);
return 0;
Print.h
#include<iostream>
using namespace std;
void lprint(void);
print.cpp:
#include<iostream>
#include"print.h"
using namespace std;
void lprint()
{
cout<<"I'm ok!\nIt's OK!"<<endl;
}
其中print.cpp和print.h生成libprint.so
调用的时候老失败显示:dlsym error,怎么回事,拿出错了