1
我想加载库library.so,当我尝试如果存在返回true,但是当我使用dlopen返回库不存在。加载.so库C++
std::ifstream ifile("library.so"); if (ifile) {
cout << "Exist!" << std::endl; }
cout << "C++ dlopen demo\n\n";
// open the library cout << "Opening hello.so...\n"; void* handle = dlopen("library.so", RTLD_LAZY);
if (!handle) {
cerr << "Cannot open library: " << dlerror() << '\n';
return 1; }
可能是ifstream对象锁定了文件对象,请在使用dlopen之前尝试执行'ifile.close()'。 – Robert 2013-05-02 10:33:41