当我开始使用 Swift 学习 iOS 开发时,我对 Objective C 的经验非常少,并且我需要使用较旧的 ObjC 库。
我的 netsdk.h 库(文件有超过 50k 行)
#ifndef DHNETSDK_H
#define DHNETSDK_H
#if (defined(WIN32) || defined(_WIN32) || defined(_WIN64))
...
#else //non-windows
#define CLIENT_NET_API extern "C"
#define CALL_METHOD
#define CALLBACK
...
基本上在阅读了与此相关的一些问题后,我认为下一行的 extern "C"
有问题
...
#define CLIENT_NET_API extern "C"
...
因此,我在许多使用 CLIENT_NET_API 的行上遇到错误,例如
expected identifier or '('
Expanded from macro 'CLIENT_NET_API'
我的第一次尝试是包装#define CLIENT_NET_API extern "C"
进入
#ifdef __cplusplus
extern "C" {
#endif
#define CLIENT_NET_API
#ifdef __cplusplus
}
#endif
但随后我在使用 CLIENT_NET_API 的所有行上收到错误 “C 不支持默认参数”
例如这些
CLIENT_NET_API BOOL CALL_METHOD CLIENT_StartBackUpCase(LLONG lLoginID, const NET_IN_START_CASE_BACK_UP* pstInParam, NET_OUT_START_CASE_BACK_UP *pstOutParam, int nWaitTime = NET_INTERFACE_DEFAULT_TIMEOUT);
CLIENT_NET_API BOOL CALL_METHOD CLIENT_StopBackUpCase(LLONG lLoginID, const NET_IN_STOP_CASE_BACK_UP* pstInParam, NET_OUT_STOP_CASE_BACK_UP *pstOutParam, int nWaitTime = NET_INTERFACE_DEFAULT_TIMEOUT);
我认为它应该以其他方式包装,但我找不到在同一行上使用 #define
和 extern
关键字的示例
最佳答案
在这种情况下:
定义 CLIENT_NET_API extern "C"
说,让 CLIENT_NET_API
为 extern "C"
因此,在您的情况下,您只需定义为空现有预处理器变量
#ifdef __cplusplus
extern "C" {
#endif
#define CLIENT_NET_API
#ifdef __cplusplus
}
#endif
关于ios - 错误: Expected identifier or '(' after usage of old Objective C library in Swift project through bridging header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57955570/