黑马程序员技术交流社区

标题: 编译报错。。。大神进。。。 [打印本页]

作者: lipeiaiwo    时间: 2014-7-24 00:58
标题: 编译报错。。。大神进。。。
看看下面这个不知道怎么就是报错呢?cc的时候加了 -framework Foundation 报的错是:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Che", referenced from:
      objc-class-ref in 1类-AWRDrA.o
  "_OBJC_IVAR_$_Che.lunzi", referenced from:
      _main in 1类-AWRDrA.o
  "_OBJC_IVAR_$_Che.shisu", referenced from:
      _main in 1类-AWRDrA.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation

代码如下:
#import <Foundation/Foundation.h>

@interface Che : NSObject
{
    @public
    int lunzi;
    int shisu;
}
@end


int main()
{
    Che *p = [Che new];
    p->lunzi = 4;
    p->shisu = 130;
   
    NSLog(@"车的轮子有%d个,车的时速是%dkm/h",p->lunzi,p->shisu);
   
    return 0;
}
作者: fantacyleo    时间: 2014-7-24 02:03
Che类只有interface,没有implementation,当然要挂
作者: ★Joean_Zhou    时间: 2014-7-24 08:57
可以不声明(有警告),但是不可以不实现
作者: lipeiaiwo    时间: 2014-7-24 14:43
fantacyleo 发表于 2014-7-24 02:03
Che类只有interface,没有implementation,当然要挂

谢谢.....




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2