运行第一行代码
程序的运行就是将高级语言编译和链接生成可执行文件加载到闪存当中,
第一课:用mac终端一些简单命令编译链接输出 “hello,Object C"
Tips:
- 获取某个文件/文件夹本地地址:直接拖入该文件到终端,自动生成该文件到地址路径;
- 按下鼠标到滚轮,在终端会copy选中到文字
Mac 终端有很多简单常用的命令行.
cd :跳转;
touch xxx.xx:创建;
open xxx.xx: 打开某文档
ls-l: 获取该文件夹下所有文件名;、
clear :清除终端所有字符
cc -c 文件名: 编译文件
cc :链接;
./ :运行 ;
1.终端跳到目标文件夹
cd /Users/m10/Desktop/0523课堂共享/代码/
2.创建.m文件
touch 第一个oc代码.m
3.打开该.m 文件
open 第一个oc代码.m
**4.在打开的.m文件里编写代码;
#include <stdio.h>
//oc 程序的入口
int main()
{
printf("hello,the world\n");
return 0;
}
linzhengjunde-Mac-mini:代码 m10$ open 01-第1个OC程序.m
//编译
linzhengjunde-Mac-mini:代码 m10$ cc -c 01-第1个OC程序.m
//列举所有该路径下的文件名
linzhengjunde-Mac-mini:代码 m10$ ls -l
total 16
-rw-r--r--@ 1 m10 staff 73 5 23 18:13 01-第1个OC程序.m
-rw-r--r-- 1 m10 staff 704 5 23 18:14 01-第1个OC程序.o
//cc 链接 可以看到生成一个 a.out 文件
linzhengjunde-Mac-mini:代码 m10$ cc 01-第1个OC程序.o
linzhengjunde-Mac-mini:代码 m10$ ls -l
total 40
-rw-r--r--@ 1 m10 staff 73 5 23 18:13 01-第1个OC程序.m
-rw-r--r-- 1 m10 staff 704 5 23 18:14 01-第1个OC程序.o
-rwxr-xr-x 1 m10 staff 8344 5 23 18:16 a.out
// ./ +文件名 :运行文件
linzhengjunde-Mac-mini:代码 m10$ ./a.out
hello,the world
linzhengjunde-Mac-mini:代码 m10$