我正在整理一个补丁,它增加了Crypto++库的可见度。根据GCC能见度的wiki:
在抛出异常的二进制文件中捕获用户定义类型的异常需要进行类型信息查找.然而,这并不是完整的故事--它变得更难了。默认情况下,符号可见性是“默认的”,但是如果链接器遇到一个隐藏的定义--只有一个--类型信息符号将永久隐藏(请记住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.
发布于 2015-03-09 15:34:31
您是否尝试过像这样导出内部类:
class Exception {};
class __declspec(dllexport) AlgorithmParametersBase
{
public:
class ParameterNotUsed : public Exception
{
public:
};
};
// exporting known type
class __declspec(dllexport) AlgorithmParametersBase::ParameterNotUsed;
不过,我没有测试上面的调用,但是它编译得很好。
https://stackoverflow.com/questions/28952886
复制相似问题