【发布时间】:2016-05-13 14:13:21
【问题描述】:
我正在将代码从 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(...)表示该函数可以抛出any异常。这类似于根本没有异常规范。
标签: c++ object visibility shared throw