如何在可见性生效时导出公共内部/嵌套类
How to export a public inner/nested class when visibility is in effect?
我正在整理一个补丁,增加了Crypto++库的可见性。根据GCC可见性维基:
在二进制文件以外的二进制文件中捕获用户定义类型的异常 抛出异常的一个需要类型信息查找...然而 这不是故事的全部 - 它变得更加困难。符号可见性为 默认情况下为"默认",但如果链接器只遇到一个定义 隐藏它 - 只有一个 - 该类型信息符号成为永久 隐藏(记住C++标准的ODR - 一个定义规则)。
我的结论:所有内容(包括基类)都需要导出或用__attribute__ ((visibility ("default")))
装饰。所以我从异常类引用中得到了一个异常列表,并且......
class CRYPTOPP_DLL AlgorithmParametersBase
{
public:
class ParameterNotUsed : public Exception
{
public:
...
}
}
然后:
cryptopp$ nm -D libcryptopp.so | c++filt | grep ParametersNotUsed
cryptopp$
如果我用class CRYPTOPP_DLL ParameterNotUsed : public Exception
重建,那么我会得到相同的结果:
class CRYPTOPP_DLL AlgorithmParametersBase
{
public:
class CRYPTOPP_DLL ParameterNotUsed : public Exception
{
public:
...
}
}
现在,我相当确定基类已导出:
$ nm -D libcryptopp.so | c++filt | grep Exception
00000000004d6980 V typeinfo for CryptoPP::Exception
0000000000230700 V typeinfo name for CryptoPP::Exception
00000000004d6bf0 V vtable for CryptoPP::Exception
我的问题:
- 如何导出内部或嵌套类,因为它似乎没有导出?
nm -D
用于验证typeinfo
信息的正确工具吗?- 我能捕捉到
ParameterNotUsed
异常吗(我怀疑不是)? - 我是否能够捕获
Exception
基类异常(我怀疑是这样)?
万一重要:
$ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
您是否尝试过像这样导出内部类:
class Exception {};
class __declspec(dllexport) AlgorithmParametersBase
{
public:
class ParameterNotUsed : public Exception
{
public:
};
};
// exporting known type
class __declspec(dllexport) AlgorithmParametersBase::ParameterNotUsed;
但是,我没有测试上述调用,但它编译得很好。
相关文章:
- 如果我将嵌套映射作为多重映射的值,如何将值插入内部映射?
- 嵌套命名空间的"using"指令,但需要命名内部命名空间
- 嵌套模板函数采用 2 个具有相同内部类型的容器
- 在模板类内部定义的枚举上的嵌套类的部分专用化
- 返回自身内部的双重嵌套类的成员函数,该类继承自从自身继承的类
- 解决具有嵌套模板化变量的 Visual Studio 内部编译器错误
- 嵌套 for 循环仅运行内部循环 (c++)
- 嵌套的C 常数数据结构,没有初始化列表或明确命名所有节点-VC 2012过早破坏了内部元素
- 在哪里放置 PRIVATE 嵌套(内部)类的非成员函数定义
- 循环时内部嵌套不会执行
- 从嵌套的私有类内部使用外部类中的C++公共变量
- 如何在可见性生效时导出公共内部/嵌套类
- openMP 嵌套并行用于循环与内部并行
- 如何为嵌套循环配置openMP以保持内部循环不并行
- 嵌套命名空间:从内部命名空间访问值
- 嵌套贴图,访问内部贴图值
- 嵌套类模板专用化未正确匹配+msvc内部错误
- dll内部定义的派生嵌套类的序列化
- 基于嵌套的内部参数专门化模板
- 在类内部引入的类名不被视为嵌套类名