如何解决如果访问静态类成员例如调用boost :: this_fiber :: get_id,dlclose不会释放库句柄
我的情况如下,无法关闭图书馆
liba.so
#include <iostream>
#include <boost/fiber/all.hpp>
using namespace std;
int func1(int)
{
cout << "this fiber id " << boost::this_fiber::get_id() << endl; // if this line is commented out then the problem resolved.
cout << "It is a func1" << endl;
return 1;
}
我从cpp文件中创建了一个库,其中指定了-fno-unique-symbol,这样它就不应保留该符号。
主要代码
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
using namespace std;
int fun(string & flName) {
void *handle;
typedef int (*fn)(int);
fn fn1;
handle = dlopen(flName.c_str(),RTLD_LOCAL|RTLD_LAZY);
fn1 = (fn)dlsym(handle,"_Z5func1I");
(*fn1)(2);
cout << "handle :" << handle << endl;
int ext_code = dlclose(handle);
printf ("end exit code %d\n",ext_code);
}
int main(void) {
std::string fileName("dirpath/liba.so");
fun(fileName);
fun(fileName);
fun(fileName);
return 0;
}
输出,当this_fiber被注释掉
- 手柄:0x234567
- 结束退出代码0
- 句柄:0x345678
- 结束退出代码0
- 手柄:0x456789
- 结束退出代码0
-----但是当this_fiber :: get_id()处于活动状态时,
- 手柄:0x234567
- 结束退出代码0
- 句柄:0x234567
- 结束退出代码0
- 手柄:0x234567
- 结束退出代码0
有人可以解释一下阻止库句柄的原因,并告诉我如何调整代码,以便我可以关闭库
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。