0
votes

I have a class that holds number ivars:

//  Answer.h

#import <Foundation/Foundation.h>


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

@end

I try to access the code here

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

and I get this error:

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
You realize that a4r()%1 will always be 0, right? - Kevin
Have you tried cleaning the project? - Kevin
Yes, I have tried cleaning the project, but did not catch the second. Thanks - TheLivingForce

1 Answers

2
votes

The compiler generates symbol _OBJC_IVAR_$_Answer.firstNumber in the data segment as part of the Answer class metadata when it processes the @implementation section for the Answer class. The data at that symbol is the offset of the firstNumber instance variable within an Answer object.

Either you aren't linking your app with a file that contains an @implementation Answer section, or the compiler hasn't seen the declaration of the firstNumber instance variable before it sees the @implementation Answer section. Check that these are all true:

  • Answer.m is included in your target's Compile Sources phase.
  • Answer.m contains an @implementation Answer section.
  • Answer.m imports Answer.h at the top of Answer.m.