5

タイトルと同じキーワードの質問がいくつ かありますが、 Objective-C の iOS 側に焦点を当てています。私の問題は、MacOS コマンド ライン ツールにあります。

基本的に何が起こっているかというと、Foundation (Cocoa) ツールが別の Foundation メソッドを呼び出す C 関数を呼び出しているということです。Foundation メソッドが C 関数から呼び出されると、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;
}

ARC は 64 ビット コンパイル済みツールで有効になり ( 32 ビット バージョンでは有効にできません)、サポートされる最小の Ma​​cOS バージョンは 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 コンパイラが処理すべきもののように思えます。

私が間違っているかもしれないことについて誰かが推測していますか?

4

0 に答える 0