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

时间:2023-03-09 06:34:37
使用code::blocks搭建objective-c的IDE开发环境 支持 @interface

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

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

Project 结构:

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

main.m

 #import <Foundation/Foundation.h>
#include "Person.h" int main (int argc, const char *argv[])
{
Person *person = [Person new];
[person Printme :@"Windy" Age:]; return ;
}

Person.h

  #import <Foundation/Foundation.h>
@interface Person : NSObject
{
//TODO:
}
-(void) Printme :(NSString*) name Age:(int) age;
@end

Person.m

 #include "Person.h"
@implementation Person
-(void) Printme :(NSString*) name Age:(int) age
{
NSLog(@"My name is %@, I am %d old",name,age);
}
@end

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

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

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

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

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

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

Ok,搞定!