1.oc 程序执行过程:
实例代码:
1>.完全兼容C语言:
// 在main.m文件里 #include <stdio.h> int main() { printf("OC程序的入口main函数\n"); return 0; }
// 终端指令 // 编译: cc -c main.m // 链接: cc main.o // 执行: ./a.out
2>.只含OC代码,不含有C代码:
#import <Foundation/Foundation.h>
1
2
3
4
5 |
// #import 和 #include 的区别 <br>// 跟#include一样,用来拷贝某个文件的内容 // 可以自动防止文件内容被拷贝多次,也就意味着头文件中不用加入下面的预处理指令 // #ifndef _STDIO_H_ // #define _STDIO_H_ // #endif |
int main()
{
NSLog(@"第2个OC程序");
return 0;
}
// 终端指令
// 编译cc –c main.m
// 链接cc main.o –framework Foundation
// 运行./a.out
3>.OC和C混用
1) 编写3个文件 main.m one.h one.c ? main.m #import "test.h" int main() { test(); return 0; } ? test.h void test(); ? test.c #include <stdio.h> #include "test.h" void test() { printf("调用了test函数\n"); } 2) 终端指令 ? 编译:cc –c main.m test.c ? 链接:cc main.o test.o ? 运行:./a.out (没有使用Foundation框架的话,就不用-framework Foundation)
01-Objective-c简介,布布扣,bubuko.com
原文:http://www.cnblogs.com/lszwhb/p/3671038.html