gpt4 book ai didi

objective-c - "Reference to ' ' is ambiguous"将纯 C header 包含到 Obj-C iOS 项目时

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:14 26 4
gpt4 key购买 nike

总结:

我遇到的错误如标题所述。我遇到 Reference to '' is ambiguous 错误。我一直无法确定问题出在哪里,无论是我的导入结构设置不正确,还是以某种方式多次包含 header 或诸如此类。

由于请求和要求,我目前正在尝试使用 Objective-C 和 C 构建单 View iOS 应用程序,同时导入自定义纯 C SDK。这是我第一次在 iOS 应用程序中使用 C,更不用说包括整个 SDK,所以我不能 100% 确定我这样做的过程是否正确,但我已经能够解决错误了编译。

SDK 文件通过 prefix.h 被包含,它被导入到单个 View Controller 的 header 中。 我也在某处读到使用 .pch 而不是 .h,但鉴于此项目的要求,我无法弄清楚如何这样做.../p>

错误:

Reference to 'E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE' is ambiguous.
  • "In file included from .../ViewController.m" -"In file included from .../ViewController.h"
  • "In file included from .../prefix.h"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE'"
Reference to 'E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH' is ambiguous.
  • "In file included from .../ViewController.m"
  • "In file included from .../ViewController.h"
  • "In file included from .../prefix.h"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH'"

对“E_EXTERNAL_DEVICE_TYPE__PRINTER”的引用不明确。

  • "In file included from .../ViewController.m"
  • "In file included from .../ViewController.h"
  • "In file included from .../prefix.h"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
  • "Candidate found by name lookup is'_E_EXTERNAL_DEVICE_TYPE__PRINTER'"
// Device.c
...
// this and other similiar lines of code that throws the error
if((deviceType == E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE) && E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH) {
CODE x = E_EXTERNAL_DEVICE_TYPE__PRINTER;
}

尝试的解决方案

奇怪的是,在我开始使用 SDKInitialize 的过程中,有一次我能够通过交互式取消注释行和调试代码行来构建和运行部分项目。但是由于某些未知原因,即使我在 ViewController.m 中评论了 SDKInitialize() 使其只是一个空的 ViewController 什么都不做,我现在还是收到了这个错误。

我也尝试过恢复旧的 git 版本,项目可以正常构建,但它仍然遇到同样的错误,这可能让我相信这可能与 XCode IDE 或某种配置设置有关。 ..

  1. 清理项目
  2. 删除了“~/Library/Developer/Xcode/DerivedData/ModuleCache/”中的所有内容
  3. 再次清洁
  4. 构建项目

已经检查过

build设置

我试过设置 always_search_user_paths = No;

Always Search User Paths = Yes;  
Header Search Paths[$(PROJECT_DIR)/.../.../.../SDK/Common] = recursive;
Header Search Paths[$(PROJECT_DIR)/.../.../.../SDK/Core] = recursive;
Header Search Paths[$(PROJECT_DIR)/.../.../.../GenericAppRoot] = non-recursive;
... etc

仅供引用 app.xcodeproj 存在于 ___/GenericAppRoot/Devices/iOS 中

文件结构

Common.h

//located in $(PROJECT_DIR)/.../.../.../SDK/Common
//Common.h
#ifndef __DTISDK_COMMON_H__
#define __DTISDK_COMMON_H__

//--------
// SDK Includes
//--------

//...

//--------------
// External Device Types
//--------------
typedef enum _E_EXTERNAL_DEVICE_TYPE
{
E_EXTERNAL_DEVICE_TYPE__PRINTER = 1,
E_EXTERNAL_DEVICE_TYPE__CARD_ENTRY_DEVICE = 2,
E_EXTERNAL_DEVICE_TYPE__PIN_ENTRY_DEVICE = 3,
} E_EXTERNAL_DEVICE_TYPE;

//...

typedef enum _E_EXTERNAL_DEVICE_CONNECTION_TYPE
{
E_EXTERNAL_DEVICE_CONNECT_TYPE__AUDIO = 1,
E_EXTERNAL_DEVICE_CONNECT_TYPE__BLUETOOTH = 2,
} E_EXTERNAL_DEVICE_CONNECTION_TYPE;

//...

#endif //__DTISDK_COMMON_H__

前缀.h

#ifndef prefix_h
#define prefix_h

#include "File.h"
#include "File.c"
#include "System.h"
#include "System.c"
#include "Common.h"
... etc

ViewController.h

#import <UIKit/UIKit.h>
#import "prefix.h"

@interface ViewController: UIViewController

@end

ViewController.m

#import "ViewController.h"
@interface ViewController()
@end

@implementation ViewController
- (void) viewDidLoad {
[super viewDidLoad];

// initialization callback from one of the SDK classes
SDKInitialize();
}
@end

任何额外的帮助或见解将不胜感激

最佳答案

您包含了 prefix.h 中的 *.c 文件,这是错误的。始终仅包含头文件 (*.h)。

当您包含实现 (*.c) 文件时,文件的内容将按原样插入,因此您会在多个地方获得相同的定义,从而导致名称冲突。

关于objective-c - "Reference to ' ' is ambiguous"将纯 C header 包含到 Obj-C iOS 项目时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38191105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com