2012-09-20 19 views
0

我有持有數量的ivars類:

// Answer.h 

#import <Foundation/Foundation.h> 


@interface Answer : NSObject{ 
    @public 
    int firstNumber; 
    int secondNumber; 
    char myOperator; 
} 

@end 

我嘗試訪問這裏的代碼

numberGroup->firstNumber = arc4random() % 1; 
    numberGroup->secondNumber = arc4random() % 10; 
    numberGroup->myOperator = arc4random() % 4; 

,我得到這個錯誤:

Ld /Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator/PowerBuilders.app/PowerBuilders normal i386 cd "/Users/jack/Desktop/Xcode/Assorted Apps/PowerBuilders" setenv MACOSX_DEPLOYMENT_TARGET 10.6 setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator -F/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator -filelist /Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Intermediates/PowerBuilders.build/Debug-iphonesimulator/PowerBuilders.build/Objects-normal/i386/PowerBuilders.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator/PowerBuilders.app/PowerBuilders

Undefined symbols for architecture i386:
"_OBJC_IVAR_$_Answer.firstNumber", referenced from: -[ViewController lesson1] in ViewController.o "_OBJC_IVAR_$_Answer.myOperator", referenced from: -[ViewController lesson1] in ViewController.o "_OBJC_IVAR_$_Answer.secondNumber", referenced from: -[ViewController lesson1] in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

+1

你意識到'a4r()%1'將始終爲0,對嗎? – Kevin

+0

您是否嘗試過清潔項目? – Kevin

+0

是的,我已經嘗試清理該項目,但沒有抓住第二個。謝謝 – TheLivingForce

回答

2

編譯器在數據段中生成符號_OBJC_IVAR_$_Answer.firstNumber,作爲Answer類元數據的一部分,當它處理@implementation部分爲Answer類。該符號處的數據是Answer對象內的firstNumber實例變量的偏移量。

要麼您沒有將您的應用程序與包含@implementation Answer部分的文件鏈接起來,要麼編譯器在看到@implementation Answer部分之前沒有看到實例變量的聲明firstNumber。檢查是否全部爲真:

  • Answer.m包含在您的目標的編譯源階段。
  • Answer.m包含@implementation Answer部分。
  • Answer.mAnswer.m的頂部輸入Answer.h
+0

編譯源相位在哪裏?它在方案編輯器中嗎? – TheLivingForce

+1

在Project Navigator中點擊您的項目文件。然後點擊目標列表中的目標。然後點擊Build Phases選項卡。 –

+0

修正了它。謝謝! – TheLivingForce

相關問題