64,267
社区成员
发帖
与我相关
我的任务
分享
void Init(void) __attribute__((constructor));
void Final(void) __attribute__((destructor));
标识一对函数,来显示模块的加载和卸载。class CMath
{
public:
void A()
{
int const es[] = { 1, 2 };
int index = 0;
printf("%d", es[index]);
}
static void B()
{
static int const es[] = { 1, 2 };
int index = 0;
printf("%d", es[index]);
}
// static void C()
// {
// int const index = 0;
// printf("%d", _es[index]);
// }
//
// static int const _es[2];
};
//int const CMath::_es[2] = {1, 2};
void Export()
{
//CMath _;
//_.A();
CMath::B();
//CMath::C();
}
void Export() __attribute__((visibility("default")));
static void _Init(void)
{
printf("module loaded.\n");
}
static void _Final(void)
{
printf("module unloaded.\n");
}
void _Init(void) __attribute__((constructor));
void _Final(void) __attribute__((destructor));
int main()
{
void *handle;
printf("dlopen ...\n");
handle = dlopen("libShare.so", RTLD_LAZY);
printf("dlopened.\n");
assert(handle);
printf("dlclose ...\n");
dlclose(handle);
printf("dlclosed.\n");
return getchar();
}
//#define INCLASS
class CMath
{
public:
static void B()
#ifdef INCLASS
{
static int es[] = { 1, 2 };
int v = es[0];
printf("%d", v);
}
#else
;
#endif
};
#ifdef INCLASS
#else
void CMath::B()
{
static int es[] = { 1, 2 };
int v = es[0];
printf("%d", v);
}
#endif
宏定义是否存在,将影响共享库在 dlclose 的时候是否可以正常卸载。
请高手指点一二,不甚感激。