我正在将代码从 Windows 移植到 CentOS,但我遇到了一个我以前从未见过的问题。
鉴于该函数声明(还有更多):
byte getValueInt8() const throw(.../*Exception*/);
我收到这个错误:
error: expected type-specifier before ‘...’ token unsigned short getValueInt8() const throw(.../*Exception*/);
当然,我查过互联网,发现这是共享对象中的可见性问题。
本站https://gcc.gnu.org/wiki/Visibility对此进行了解释,但我在阅读时已经这样做了。
我的定义是:
#if defined(_MSC_VER)
#include <winsock2.h>
#ifdef MFTINTERFACE_EXPORTS
#define EXPORT_IMPORT __declspec(dllexport)
#else
#define EXPORT_IMPORT __declspec(dllimport)
#endif
#elif defined(_GCC)
#include <arpa/inet.h>
#include "CmnSocketsDef.h"
#include "CmnDefs.h"
#define EXPORT_IMPORT __attribute__((visibility("default")))
#else
#define EXPORT_IMPORT
#define IMPORT
#pragma warning Unknown dynamic link import/EXPORT_IMPORT semantics.
#endif
当然,所有的 EXPORT_IMPORT 都在我的代码中设置好了。
修改前的代码在Windows下编译。
最佳答案
throw(...)
作为异常规范是不合法的 c++。
我只能假设您遇到过 Microsoft abomination 扩展。
您需要将其删除。在任何情况下,唯一在现实中有意义的异常说明符是 nothrow
(如果您使用的是古老的编译器,则为 throw()
)。
的确,这是确凿的证据:
https://msdn.microsoft.com/en-us/library/wfa0edys.aspx
弃用建议:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3051.html
关于c++ - 抛出和共享对象的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37212298/