2011-11-11 67 views
7

我對iOS開發比較陌生,並且正在嘗試實現CocoaLumberjack日誌記錄。CocoaLumberjack錯誤:未找到符號:_objc_storeStrong

我從https://github.com/robbiehanson/CocoaLumberjack下載了最新的源代碼,在我的項目中包含了所需的文件,進行了必要的代碼更改,並且得到了下面的運行時鏈接器錯誤。

環境是Xcode 4.2 Build 4C199,項目Target設置爲Device = iPad和DeploymentTarget = 4.3。該項目最初是使用retain/release編寫的,所以我保留原始源代碼,爲我使用的伐木工人文件添加編譯器標誌「-fobjc-arc」:DDFileLogger.m,DDLog.m和DDTTYLogger.m 。

控制檯輸出爲:

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Fri Sep 16 06:56:50 UTC 2011) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001 
sharedlibrary apply-load-rules all 
target remote-mobile /tmp/.XcodeGDBRemote-10996-56 
Switching to remote-macosx protocol 
mem 0x1000 0x3fffffff cache 
mem 0x40000000 0xffffffff none 
mem 0x00000000 0x0fff none 
[Switching to process 11779 thread 0x2e03] 
[Switching to process 11779 thread 0x2e03] 
dyld: lazy symbol binding failed: Symbol not found: _objc_storeStrong 
    Referenced from: /var/mobile/Applications/32E4EEB9-765E-4C72-83C8-F5707253AA99/Demo.app/Demo 
    Expected in: /usr/lib/libobjc.A.dylib 

dyld: Symbol not found: _objc_storeStrong 
    Referenced from: /var/mobile/Applications/32E4EEB9-765E-4C72-83C8-F5707253AA99/Demo.app/Demo 
    Expected in: /usr/lib/libobjc.A.dylib 

warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame. 
(gdb) 

我的項目初​​始化如下的環境中,fileLogger在相應AppDelegate.h文件中定義的實例變量:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    /* 
    * Configure the Lumberjack logging framework (we'll use it instead of NSLog) 
    */ 

    // the TTY logger is the Xcode console 
    [DDLog addLogger:[DDTTYLogger sharedInstance]]; 

    // we'll also use a file logger 
    fileLogger = [[DDFileLogger alloc] init]; 
    fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling 
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7; 
    [DDLog addLogger:fileLogger]; 


    // Override point for customization after application launch. 
    DDLogInfo(@"didFinishLaunchingWithOptions: entered"); 

    // create instance of the view controller 
    MainViewController *aViewController = [[MainViewController alloc] 
              initWithNibName:@"MainView" bundle:nil]; 
    self.mainViewController = aViewController; // same as: [self setMainViewController:aViewController]; 
    [aViewController release]; 

    // Add the main view controller's view to the window and display. 
    self.window.rootViewController = self.mainViewController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

有沒有人遇到過這種問題,並知道解決方案或解決方法?我甚至有可能做什麼......在項目中混合使用ARC和非ARC文件?

+0

找到一個關於遷移到ARC(自動引用計數)的好教程:http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1。很明顯,支持混合ARC和非ARC文件,但並非ARC的所有功能都向後兼容iOS 4 - 本教程中的評論「如果使用'weak'屬性或'__weak'變量,那麼你的應用程序將無法在iOS 4上工作。「在伐木工人的文件中沒有看到任何弱變量的使用,錯誤是關於「_objc_storeStrong」,所以我仍然不確定原因。 – Alan

回答

4

我剛纔聽到後面從的CocoaLumberjack開發者之一,這是他說:

There seems to be a bug in (maybe) the LLVM compiler. Here's what I've discovered:

If you have an Xcode project without ARC turned on by default, and you have a file that uses ARC (via -fobjc-arc), and that file attempts to alloc/init stuff within '+ (void)initialize', then it will blow up at runtime.

It seems to work, however, if you convert the project to ARC...

編輯:從開發商的其他信息:

The 1.2.3 tag can be used without ARC.

You can grab an archive from here:

https://github.com/robbiehanson/CocoaLumberjack/tags

8

以供將來參考,這似乎是當前Xcode工具鏈的一個缺點,噹噹前構建的目標關閉ARC支持(並使用啓用ARC的靜態庫)時,似乎忘記包含ARC庫。您可以輕鬆強制鏈接器使用-fobjc-arc標誌包含庫,請參閱此related question以獲取完整說明。

相關問題