未找到符号:MacOS命令行工具中的_objc_retainAutoreleasedReturnValue

时间:2013-02-19 17:37:44

标签: macos osx-lion automatic-ref-counting llvm-clang

couple questions 与标题具有相同的关键字,但它们专注于Objective-C的iOS端。我的问题是使用MacOS命令行工具。

基本上发生的事情是Foundation(Cocoa)工具正在调用一个C函数,最终调用另一个Foundation方法。并且当从C函数调用Foundation方法时,就是在运行时抛出“Symbol not found: _objc_retainAutoreleasedReturnValue”错误的地方。

代码如下所示:

log.h

@interface Log : NSObject {

}

@end

void RemoveLogFile(NSString * theLogFile);

log.m

#import "Log.h"

@implementation Log

@end

// this is a C-style function
void RemoveLogFile(NSString * theLogFile)
{
    NSString * logFileName;

    NSLog( @"about to allocate a filename" );

// crash can happen in either case below
#if 1
    logFileName = [NSString stringWithFormat: @"%@.log", theLogFile];
#else
    logFileName = [[NSString alloc] initWithFormat: @"%@.log", theLogFile];
#endif

    NSLog( @"done allocating");
}

的main.m

#import <Foundation/Foundation.h>
#import "Log.h"

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSString* outPath = [[NSString alloc] initWithFormat: @"%@/MyLogFile", @"/tmp/"];
        NSLog( @"past out path alloc");
        RemoveLogFile(outPath);
        NSLog( @"done with the test");
    }
    return 0;
}

为64位编译工具(it can't be turned on for the 32-bit version)启用ARC,支持的最低MacOS版本为10.6。

在MacOS 10.7中调用该工具时,它会立即崩溃,并显示如下日志:

Process:         com.dautermann.Doughnuts [540]
Path:            /Library/PrivilegedHelperTools/com.dautermann.Doughnuts
Identifier:      com.dautermann.Doughnuts
Version:         ??? (1.0)
Code Type:       X86-64 (Native)
Parent Process:  launchd [1]

Date/Time:       2013-02-19 05:02:48.337 -0800
OS Version:      Mac OS X 10.7 (11A390)
Report Version:  8

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000

Application Specific Information:
objc[540]: garbage collection is OFF

Dyld Error Message:
  Symbol not found: _objc_retainAutoreleasedReturnValue
  Referenced from: /Library/PrivilegedHelperTools/com.dautermann.Doughnuts
  Expected in: /usr/lib/libobjc.A.dylib

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   dyld                            0x00007fff5fc0106d dyld_fatal_error + 1
1   dyld                            0x00007fff5fc04918 dyld::fastBindLazySymbol(ImageLoader**, unsigned long) + 128
2   libdyld.dylib                   0x00007fff925f0716 dyld_stub_binder_ + 13
3   ???                             0x0000000100004030 0 + 4294983728
4   com.dautermann.Doughnuts    0x0000000100001523 0x100000000 + 5411
5   com.dautermann.Doughnuts    0x0000000100001470 0x100000000 + 5232

我受过良好教育的猜测(在其他人的帮助下)是我可能需要传入“char *”,或者我必须在某处声明“_unsafe_unretained”。这肯定是现代Xcode 4.6编译器应该为我处理的东西。

任何人都有任何猜测我可能做错了什么?

0 个答案:

没有答案