使用code::blocks搭建objective-c的IDE开发环境 支持 @interface

来源:互联网 发布:手机视频剪辑合成软件 编辑:程序博客网 时间:2024/05/17 06:36

大多是写了一个Helloworld 就结束了,今天试了试 添加了一个 @interface,就是加一个 .h 文件 和一个 .m文件。编译时报错 

Project 结构:

main.m

复制代码
 1 #import <Foundation/Foundation.h> 2 #include "Person.h" 3  4 int main (int argc, const char *argv[]) 5 { 6     Person *person = [Person new]; 7     [person Printme :@"Windy" Age:34]; 8  9     return 0;10 }
复制代码

Person.h

复制代码
1  #import <Foundation/Foundation.h>2  @interface Person : NSObject3  {4     //TODO:5  }6  -(void) Printme :(NSString*) name Age:(int) age;7  @end
复制代码

Person.m

复制代码
1 #include "Person.h"2 @implementation Person3  -(void) Printme :(NSString*) name Age:(int) age4  {5      NSLog(@"My name is %@, I am %d old",name,age);6  }7 @end
复制代码

编译出错:obj\Debug\main.o:main.m:(.data+0x58)||undefined reference to `__objc_class_name_Person|.

代码是没问题的,就是少了一下步骤:

 将 "Person.m"文件的 "Compile File" 和 "Link File" 勾上.

选中"Person.m"->右键->"Properties..."->"Build"选项

Ok,搞定!

0 0