Objective-C,通常写作ObjC和较少用的Objective C或Obj-C,是扩充C的面向对象编程语言。它主要使用于Mac OS X和GNUstep这两个使用OpenStep标准的系统,而在NeXTSTEP和OpenStep中它更是基本语言。
C函数文件名SystemFile.h,代码如下:
#import <Foundation/Foundation.h> BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);
文件名SystemFile.mm执行调用代码如下:
#import "SystemFile.h" #import <sys/xattr.h> #import <Support/Support.h> static const char* attrName = "com.apple.MobileBackup"; BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url) { BOOL operationResult = NO; return operationResult; }
AddSkipBackupAttributeToItemAtURL 从另一个应用程序部分的一切都是确定,除了从块哪里调用函数的一个地方。
__block UpdateFileAsyncOperation* selfOperation = self; _contentDownloader.completionBlock = ^(NSData* data) { [data saveForcedToPath:selfOperation.filePath]; NSURL* fileUrlWithScheme = [NSURL fileURLWithPath:selfOperation.filePath]; AddSkipBackupAttributeToItemAtURL(fileUrlWithScheme); [runLoop removePort:port forMode:NSDefaultRunLoopMode]; [selfOperation completeOperation]; };
未定义的符号的 i386 体系结构:"AddSkipBackupAttributeToItemAtURL"的引用从: __36-[UpdateFileAsyncOperation 启动] _block_invoke UpdateFileAsyncOperation.o ld: 找不到架构 i386 铿锵的代号: 错误: 链接器命令失败,退出代码为 1 (使用-v 查看调用)
解决方式:
文件扩展名为".m",其他文件是扩展名为".mm",在 SystemFile.h 文件中的下一个宏,具体如下:
#ifdef __cplusplus extern "C" { #endif BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url); #ifdef __cplusplus } #endif