【问题标题】:GData ObjC - Duplicate Interface Definition ErrorGData ObjC - 重复接口定义错误
【发布时间】:2012-05-25 06:26:26
【问题描述】:

我正在尝试使用 GData ObjC 库将视频从 iPhone 上传到 Youtube。

当我在添加库后尝试构建我的项目时(在此处显示: svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/gdata-objectivec-client-read-only),我不断收到错误 -Duplicate interface definition for class 'GDataHTTPUploadFetcher'- 在 GDataServiceBase.m 中。

但是,当我在一个新项目中执行相同操作时,我根本不会遇到任何问题。我检查了所有的导入和项目设置,它们都是一样的。

我应该寻找什么来解决这样的问题?


附加信息:

(在 cmets 中回答 Till 的一个问题,因为我对类别不是很确定)

GDataHTTPUploadFetcher.h中,界面是这样的:

@interface GDataHTTPUploadFetcher : GDataHTTPFetcher {

GDataHTTPFetcher *chunkFetcher_;
BOOL needsManualProgress_
NSURL *locationURL_;
// uploadData_ or uploadFileHandle_ may be set, but not both
NSData *uploadData_;
NSFileHandle *uploadFileHandle_;
NSInteger uploadFileHandleLength_;
NSString *uploadMIMEType_;
NSUInteger chunkSize_;
BOOL isPaused_;

.
.
.

}

+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                      uploadData:(NSData *)data
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;

+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                uploadFileHandle:(NSFileHandle *)fileHandle
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;

- (id)initWithRequest:(NSURLRequest *)request
       uploadData:(NSData *)data
 uploadFileHandle:(NSFileHandle *)fileHandle
   uploadMIMEType:(NSString *)uploadMIMEType
        chunkSize:(NSUInteger)chunkSize;

- (void)pauseFetching;
- (void)resumeFetchingWithDelegate:(id)delegate;
- (BOOL)isPaused;



@end

GDataHTTPUploadFetcher.m中,界面是这样的:

@interface GDataHTTPUploadFetcher (InternalMethods)
- (void)uploadNextChunkWithOffset:(NSUInteger)offset;
- (void)uploadNextChunkWithOffset:(NSUInteger)offset
            fetcherProperties:(NSDictionary *)props;
- (void)destroyChunkFetcher;

- (void)uploadFetcher:(GDataHTTPFetcher *)fetcher
     didSendBytes:(NSInteger)bytesSent
   totalBytesSent:(NSInteger)totalBytesSent
totalBytesExpectedToSend:(NSInteger)totalBytesExpected;

- (void)reportProgressManually;

- (NSUInteger)fullUploadLength;

// private methods of the superclass
- (void)invokeSentDataCallback:(SEL)sel
                    target:(id)target
           didSendBodyData:(NSInteger)bytesWritten
         totalBytesWritten:(NSInteger)totalBytesWritten
 totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

- (void)invokeStatusCallback:(SEL)sel
                  target:(id)target
                  status:(NSInteger)status
                    data:(NSData *)data;

- (BOOL)invokeRetryCallback:(SEL)sel
                 target:(id)target
              willRetry:(BOOL)willRetry
                  error:(NSError *)error;
@end

GDataServiceBase.m中,界面是这样的:

@interface GDataHTTPUploadFetcher : GDataHTTPFetcher
+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                      uploadData:(NSData *)data
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;
+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                uploadFileHandle:(NSFileHandle *)uploadFileHandle
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;
- (void)pauseFetching;
- (void)resumeFetchingWithDelegate:(id)delegate;
- (BOOL)isPaused;
@end

但问题是,此代码只会在现有项目之一中产生问题,而不会在新项目中产生问题。

【问题讨论】:

  • 如果您搜索 @implementation GDataHTTPUploadFetcher 会发生什么?您是否在 2 个文件中看到它?
  • 不,它只存在于一个文件中。但是当我搜索“@interface GDataHTTPUploadFetcher”时,它在 3 个文件中找到:GDataHTTPUploadFetcher.h/.m 和 GDataServiceBase.m
  • 我假设您在实现文件 (.m) 中找到的接口定义实际上是类别,对吗?
  • 我更新了我的问题,来回答你的问题。但就像我说的,问题是这段代码只在我现有的一个项目中存在问题,而在新项目中没有。
  • 请同时附上GDataHTTPUploadFetcher.h的相关部分

标签: iphone objective-c ios xcode cocoa-touch


【解决方案1】:

检查您的 Target -> Build Phases -> Compile Sources 是否可能包含 GDataServiceBase.m 两次。如果是这样,请从该列表中删除一个引用。

还要彻底检查所有导入/包含,看看它们是否可能包含实现文件 (.m)。在GDataServiceBase.m 上进行全局搜索即可。

也许您在标题中的某处使用了#include 而不是#import。现在,如果您这样做,则包含该标头的标头或实现文件中同一标头的另一个 #include 将导致双重定义。 #import 即使没有保护定义也能完美工作,而 #include 需要这些来防止双重定义。

在您发布代码后,它变得很明显。您引用的那些来源显然是对同一类的双重定义。我只能猜测其中的原因; 直截了当的糟糕设计


最后,原因

显然GDataServiceBase.mGDataHTTPUploadFetcher.h 定义了同一个类:GDataHTTPUploadFetcher。这当然没有意义。我无法回答作者为什么这样做,也许它只是一个过时的实现文件,不应该再编译了。无论如何,只需从GDataServiceBase.m 中删除整个@interface 块,直到并包括第一个@end。 第三个接口定义(在GDataHTTPUploadFetcher.m 内)实际上定义了一个类别——您可以看到,因为它在类/类别名称(InternalMethods) 后面包含括号。顺便说一句,原作者不应该将它们命名为InternalMethods,而只是打开和关闭括号()。但这里的一切都是他的错,不是你的:D。

【讨论】:

  • 我明白你的意思,但我检查了编译源部分,它只包含一次 GDataService.m。
  • 查看我最新添加的另一张照片。
  • 也试过了。仍然没有运气。非常感谢您的补充。
  • @ShahzebKhan 新想法,觉得值得一试 - 看看我的最新编辑
  • 也检查过,直到。再次感谢您的补充。
【解决方案2】:

我不得不将所有代码移到一个新项目中,然后一切正常。

显然,我在项目设置中搞砸了一些东西。

非常感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 2012-09-07
    • 2013-07-29
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 2012-03-18
    相关资源
    最近更新 更多