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。应用程序/PowerBuilders

体系结构 i386 的未定义符号:
“_OBJC_IVAR_$_Answer.firstNumber”,引用自:ViewController.o 中的-[ViewController 第 1 课]“_OBJC_IVAR_$_Answer.myOperator”,引用自:ViewController.o 中的-[ViewController 第 1 课]“_OBJC_IVAR_$_Answer .secondNumber”,引用自:ViewController.old 中的 -[ViewController 课程 1]:未找到架构 i386 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

4

1 回答 1

2

编译器在处理类的部分时,会_OBJC_IVAR_$_Answer.firstNumber在数据段中生成符号作为Answer类元数据的一部分。该符号处的数据是对象内实例变量的偏移量。@implementationAnswerfirstNumberAnswer

要么您没有将应用程序与包含@implementation Answer节的文件链接,要么编译器firstNumber在看到节之前没有看到实例变量的声明@implementation Answer。检查这些是否都是真的:

  • Answer.m包含在目标的编译源阶段。
  • Answer.m包含一个@implementation Answer部分。
  • Answer.mAnswer.h顶部的导入Answer.m
于 2012-09-20T03:32:30.000 回答