gpt4 book ai didi

objective-c - hello world 中架构 x86_64 的 undefined symbol

转载 作者:行者123 更新时间:2023-12-02 21:42:39 24 4
gpt4 key购买 nike

今天我正在学习 Objective-C,没有 Xcode,遵循这个 Guide

这是 Hello World :

ma​​kclass.m

#import "makclass.h"
#import <stdio.h>

@implementation MakClass

-(void) age {
printf("Age is %d", age);
}

-(void) setAge: (int) a {
age = a;
}

+(void) say {
printf("Haha");
}
@end

ma​​kclass.h

#import <Foundation/NSObject.h>
@interface MakClass: NSObject {
int age;
}

-(void) age;
-(void) setAge: (int) a;
+(void) say;
@end

helloworld.m

#import <stdio.h>
#import "makclass.h"
int main(void) {
printf("Hello World");
MakClass *makclass = [[MakClass alloc] init];
[makclass setAge: 1];
[makclass age];
[MakClass say];
[makclass release];
return 0;
}

并且 clang helloworld.m 给我以下错误:

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MakClass", referenced from:
objc-class-ref in helloworld-XEijke.o
"_objc_msgSend", referenced from:
_main in helloworld-XEijke.o
"_objc_msgSend_fixup", referenced from:
l_objc_msgSend_fixup_alloc in helloworld-XEijke.o
l_objc_msgSend_fixup_release in helloworld-XEijke.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

您需要确保传递框架和所有文件:

clang -framework Foundation -o helloworld helloworld.m makclass.m

关于objective-c - hello world 中架构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20088019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com