2018.7.19

编译器vim有三个模式:插入模式,命令模式,低行模式。

按“i”可进入到插入模式。按“Esc”会进入命令模式。

在命令模式中:x可以删除字符,dd表示删行,p表示粘贴,yy表示复制,u表示撤销。

按“shift+:”可以进入到低行模式,此时wq表示保存并退出。

vim hello.c +10 表示打开hello.c并跳的第10行。在命令模式下用/表示查找,n表示从当前位置往下查找,shift+n表示从当前位置向上查找。

配置vimrc :set autoindent表示自动缩进。

                    set shiftwidth=4与set tabstop表示按下tab后光标则向后退4格。

                    set number表示设置行号。

                    syntax on表示关键字高亮。

在低行模式下,%s/char /int/g 表示把所有的char替换成int,g表示全部。

扫描二维码关注公众号,回复: 2484739 查看本文章

sp xx.c表示打开xx.c文件。

编译的四大步骤:

一、.预处理:处理以#为开头的代码,包括头文件(#include)头文件展开,宏定义(#define)宏替换,条件编译(#if)

#if 0注释(这一部分代码不编译)

gcc -E hello.c -o hellohello.i;(hello.i是文本文件)

二.编译:1.语法检查,2.把C代码翻译成汇编代码。

gcc -S hello.i -o hello.s;(hello.s是文本文件)

三汇编:把汇编语言编译成二进制文件。

gcc -c hello.s -o hello.o(hello.o表示为二进制文件)

四。连接:连接程序需要用到的库文件。

gcc -o hello.o -o hello.

若把两文件联合编译:

设已建立hello.c与print.c文件

hello:#include<stdio.h>

           int main()

{

print();

}

print.c:#include<stdio.h>

void print

{

printf("aaaa\n");

}

输入:

gcc -E hello.c -o hello.i

gcc -S hello.i -o hello.s

gcc -c hello.s -o hello.o

gcc -c print.c -o print.o

gcc hello.o print.o -o hello

Makefile规格的基本格式:Target(目标):dependency(依赖)

                                            (Tab字符)commond

例:hello:hello.c

               gcc hello.c -o hello 

或 Target=hello

     Object=hello.c

     $(Target)=$(Object)

     gcc $(Object) -o $(Target)

Makefile的隐含规则:

Target =hello
Object =hello.o print.o
$(Target):$(Object)
    gcc $(Object) -o $(Target)

Makefile的删除用法:

Target =hello
Object =hello.o print.o
$(Target):$(Object)
    gcc $(Object) -o $(Target)
.PHONY:clean

clean:
    rm *.o hello

猜你喜欢

转载自blog.csdn.net/weixin_42720729/article/details/81121426