小编gav*_*uld的帖子

dlclose() 不适用于工厂函数和函数中的复杂静态?

我正在制作一个简单的插件框架,我希望能够在其中 dlopen() 共享库(即插件),检查和使用提供的任何工厂函数并最终 dlclose() 它,不留痕迹。

我的工厂系统很简单,只有一个导出函数,它返回一个指向公共基类的指针。为了检查插件是否已正确卸载,我有一个静态对象,其析构函数从主程序设置了一个 bool。

这是主程序:

// dltest.cpp follows. Compile with g++ -std=c++0x dltest.cpp -o dltest -ldl
#include <dlfcn.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
    if (argc > 1)
    {
        void* h = dlopen(argv[1], RTLD_NOW|RTLD_LOCAL);
        if (!h)
        {
            cerr << "ERROR: " << dlerror() << endl;
            return 1;
        }
        bool isFinilized = false;
        *(bool**)dlsym(h, "g_finilized") = &isFinilized;
        cout << boolalpha << isFinilized << endl;
        if (dlclose(h))
        {
            cerr << "ERROR: " << dlerror() …
Run Code Online (Sandbox Code Playgroud)

c++ linux gcc dlopen c++11

3
推荐指数
1
解决办法
1632
查看次数

标签 统计

c++ ×1

c++11 ×1

dlopen ×1

gcc ×1

linux ×1