ios - 错误: Expected identifier or '(' after usage of old Objective C library in Swift project through bridging header

标签 ios objective-c swift xcode

当我开始使用 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);

我认为它应该以其他方式包装,但我找不到在同一行上使用 #defineextern 关键字的示例

最佳答案

在这种情况下:

定义 CLIENT_NET_API extern "C"

说,让 CLIENT_NET_APIextern "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/

相关文章:

ios - 模拟 CKContainer 用于单元测试

ios - NSMetadataQuery isUpdating 在 Reachability 更改为 none 后中断 Swift 4

ios - 展示广告时 Facebook 受众网络崩溃

javascript - iOS UIAutomation 无法访问 TableView

objective-c - 在 UITableViewCell 中的任意位置向左或向右滑动以删除没有删除按钮的单元格?

objective-c - NSTask 调用命令top。获取错误

ios - 当他们已经是联系人时,使用 CallKit 识别来电者

ios - 为空 UITableView 编写条件语句

ios - 如何防止在 Swift 中从 UIImagePickerController 自动保存图像?

ios - 单击按钮重置重新排序的 TableView 行