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

网上有许多的关于 《使用code::blocks搭建objective-c的IDE开发环境》的文章。

大多是写了一个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 }
View Code

Person.h

1  #import <Foundation/Foundation.h>
2  @interface Person : NSObject
3  {
4     //TODO:
5  }
6  -(void) Printme :(NSString*) name Age:(int) age;
7  @end
View Code

Person.m

1 #include "Person.h"
2 @implementation Person
3  -(void) Printme :(NSString*) name Age:(int) age
4  {
5      NSLog(@"My name is %@, I am %d old",name,age);
6  }
7 @end
View Code

编译出错: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,搞定!

posted @ 2014-03-17 16:24  刘雨赣  阅读(308)  评论(0编辑  收藏  举报