====================VI编辑器===================================
1.命令模式
2.插入模式
3.末行模式
ZZ:保存并退出
w
w!
q
q!
wq
h 左
j 下
k 上
l 右
0 行首
$ 行尾
w 下移一个字
nw 下移n个字
b 左移一个字
nb 左移n个字
( 句首
) 句尾
{ 段首
} 段末
ctrl + c :进入命令模式
x 删除一个字符
nx 删除多个字符
dw 删除一个字
ndw 删除多个字
db 光标前一个字
ndb 光标前n个字
d0 光标到句首
d$ 光标到句尾
dd 当前行
ndd 当前开始n行
d( 字符到句首
d) 字符到句尾
d{ 字符到段首
d} 字符到段尾
u 取消前一次操作
插入可编辑
i
a
文本查找
?string <enter>
/string <enter>
n 向文件头方向重复查找
N 向文件尾
替换
:s/oldstr/newstr
替换所有
:s/ordstr/newstr/g
:1,10s/order/newstr/g
:1,$s/oldstr/newstr/g
文件复制粘贴
yw 光标到字尾复制
nyw 光标后n个字符
yb 光标向左复制一个字
nyb 光标向左n个字
y0 光标到句首
y$ 光标到句末
yy 复制当前行
nyy 复制N行
p 光标位制后插入
P 光标位制前插入
np 光标后复制n次
nP 光标前复制N次
编译过程:
1.预处理pre-processing -E
这阶段输入.c/.C:主要处理源文件中的#ifdef #include #define预处理命令,生成一个中间文件.i
gcc -E test.c -o test.i
2.编译 compiling -S
输入的中间文件是.i,编译后生成汇编语言.s
gcc -S test.i -o test.s
3.汇编 Assembling -c
将汇编文件test.s 转换成二进制机器代码.o
gcc -c test.s -o test.o
4.链接 Linking
生成可执行文件
gcc test.c -o test
压缩
tar -czvf test.tar.gz test*
解压
tar -xzvf test.tar.gz
gcc -o test testname.c other1.c other2.c
-g 产生调试gdb所必需的符号信息
-O/-O2 优化
-Wall 输出警告
-w 关闭警告
-Ldirname : 加到程序库文件搜索 默认:/usr/lib
-lname : 链接库 -lm表libm.a,在-L指定目录下
gcc test.c -o test -L/usr/lib -lm
==================调试器 gdb===============================
调试可执行文件
如果使一个可执行文件被gdb调试,那么使用gcc时需要加入-g选项。
gcc -g test.c -o test
gdb test
显示源代码
list : 显示10行
list 5,10 :显示5-10行
list get_sum : 显示get_sum函数代码
如果在调试中要运行linux命令,可以在gdb提示符下输入shell命令
shell ls
查找
search 字符串
forward 字符串
reverse-search 字符串
执行程序
run
获得帮助
help list
help all
设置管理断点
以行号设置断点
break 7
以函数名设置断点
break get_sum
以条件表达式断点
break 行号/函数名 if 条件
整个过程运行当条件表达式的值发生变发
watch 条件表达式
watch i==99
删除断点
clear 6
继续运行
contiune
打印变量i值
print i
print sum
下一步
next
查看当前中断点
info breakpoints
使中断失效
disable 2
删除断点
clear 行号/函数名/断点
delete num
查看设置变量值
print 变量
print 变量=值
whatis 变量:查看变量类型
变量赋值
set variable 变量=值
控制程序运行
continue
kill
next
step
================make 使用和makefile编写====================
有一个用来维护程序模块关系和生成可执行程序的工具make
它可以根据程序模块的修改情况重新编译链接生成中间代码或最终的可执行文件
执行make命令,需要一个名为Makefile /makefile文本文件
它定义了模块间的依赖关系,指定文件的编译顺序,以及编译所使用的命令。
make从Makefile文件中获取模块间的依赖关系,判断哪些文件过时了,根据这些信息make确定哪些文件需要重新
编译,然后使用Makefile中的编译命令进行编译。
Makefile
main:main.o module1.o module2.o
gcc main.o module1.o module2.o -o main
main.o:main.c head1.h head2.h common_head.h
gcc -c main.c
module1.o: module1.c head1.h
gcc -c module1.c
module2.o: module2.c head2.h
gcc -c module2.c
Makefile基本构成
一条规则指定一个或多个目标文件,目标文件后面跟的是编译生成该目标所依赖的文件或模块,
最后是生成或更新目票文件所使用的命令。
目标文件列表 分隔符 依赖文件列表 [;命令]
[命令]
[命令]
make如何解释执行Makefile
make
gcc -c main.c
gcc -c module1.c
gcc -c module2.c
gcc main.o module1.o module2.o -o main
make -f othername
make --file=othername
Makefile文件的构成
显式规则
隐含规则
使用变量
文件指示
注释
module1.o : head1.h
等价于
module1.o : module1.c head1.h
gcc -c module1.c -o module1.o
main : main.o module1.o module2.o
gcc main.o module1.o module2.o -o main
main.o:head1.h head2.h common_head.h
module1.o:head1.h
module2.o:head2.h
$表示使用变量或调用函数
规则的主要思想:目标文件的内容由依赖文件决定,依赖文件的任何一处
改动,将导致目前已经存在的目标文件的过时。
foo : foo.c | somelib
gcc -o foo foo.c somelib
| 前面的文件是普通依赖文件,如果foo.c过时,将导致foo重新生成。
而 | 后面的文件过时,foo 不会被重新生成,也就是第二行命令不会执行。
一条规则中可以有一个或多个命令行,以Tab开头,后加+ - @再写命令
- 执行命令时遇到错误,继续执行不退出make
+ 本行命令始终被执行
@ 执行本行命令时不在屏幕上打印内容
file.o: file.c head1.h head2.h
-mv file.o /tmp
gcc -c file.c
clean:
-rm -f *.o
make clean
all : program1 program2 program3
.PHONY : all
program1: program1.c utils.h
gcc -o program1 program1.c
program2: program2.c
gcc -o program2 program2.c
program3: program3.c comm.h utils.h
gcc -o program3 program3.c
含多个目标规则
module1.o module2.o module3.o : command.h
相当于
modlue1.o : module1.c command.h
gcc -c module1.c -o comdule1.o
modlue2.o : module2.c command.h
gcc -c module2.c -o comdule2.o
modlue3.o : module3.c command.h
gcc -c module3.c -o comdule3.o
搜索目录
VPATH指定依赖
VPATH=/usr/src:../headers
使用变量
变量名 赋值符 变量值
赋值符
= := += ?=
系统变量
$@
$?
$<
$*
引用变量
$(变量名)
${变量名}
定义变量
= 赋值变量递归展开变量
:= 赋值的变量是立即展开变量
foo = $(bar)
bar = $(ugh)
ugh = Huh
all :
echo $(foo)
x := foo
y := $(x) bar
x := later
?= 只有此变量在之前没有赋值情况下会对这个变量赋值
FOO ?= bar
objects = main.o foo.o bar.o utils.o
objects += another.o
预定义变量
CC = cc
CFLAGS = -o
MAKE = make
module1.o : module1.c head1.h
$(CC) -c modlue1.c
自动变量
$@ 表示一个规则中的目标文件
file1.o file2.o : header.h
cp $@ /backup
file1.o : file1.c header.h
cp $@ /backup
gcc -c file1.c -o file1.o
file2.o : file2.c header.h
cp $@ /backup
gcc -c file2.c -o file2.o
$% 当规则的目标文件是一个静态库文件时,表一个成员名
foo.a $%表foo.a
$< 第一个依赖文件名
file1.o file2.o : header.h
cp $@ /backup
$> 库名
$? 所有目标文件新的依赖列表,以空格分开
$^ 所有依赖文件列表,不重复
$+ 所有依赖文件列表,可重复
$* 目标文件去掉后缀后的名称
file1.o file2.o : header.h
gcc -c $*.c -o $@
$(CC) $(CFLAGS) $@ $<
库中成员
库名(成员名1 成员2)
库名(成员1) 库名(成员2)
mylib.a(file.o)
表示静态库mylib.a(以.so结尾的是动态库)中有一个名为file.o的文件
建立和维护一个库时,将库名作为目标名,把希望放到库的文件作依赖文件
mylib.a : mylib(file1.o) mylib(file2.o) mylib(file3.o)
mylib.a : mylib(file1.o file2.o file3.o)
ar -ruv 库名 目标文件名
mylib : mylib(file1.o)
gcc -c file1.c
ar -ruv mylib file1.o
rm -f file1.o
mylib:mylib(file2.o)
gcc -c file2.c
ar -ruv mylib file2.o
rm -f file2.o
mylib:mylib(file1.o file2.o file3.o)
ar -ruv $@ $?
rm -f $?
file1.o file2.o file3.o :
1.命令模式
2.插入模式
3.末行模式
ZZ:保存并退出
w
w!
q
q!
wq
h 左
j 下
k 上
l 右
0 行首
$ 行尾
w 下移一个字
nw 下移n个字
b 左移一个字
nb 左移n个字
( 句首
) 句尾
{ 段首
} 段末
ctrl + c :进入命令模式
x 删除一个字符
nx 删除多个字符
dw 删除一个字
ndw 删除多个字
db 光标前一个字
ndb 光标前n个字
d0 光标到句首
d$ 光标到句尾
dd 当前行
ndd 当前开始n行
d( 字符到句首
d) 字符到句尾
d{ 字符到段首
d} 字符到段尾
u 取消前一次操作
插入可编辑
i
a
文本查找
?string <enter>
/string <enter>
n 向文件头方向重复查找
N 向文件尾
替换
:s/oldstr/newstr
替换所有
:s/ordstr/newstr/g
:1,10s/order/newstr/g
:1,$s/oldstr/newstr/g
文件复制粘贴
yw 光标到字尾复制
nyw 光标后n个字符
yb 光标向左复制一个字
nyb 光标向左n个字
y0 光标到句首
y$ 光标到句末
yy 复制当前行
nyy 复制N行
p 光标位制后插入
P 光标位制前插入
np 光标后复制n次
nP 光标前复制N次
编译过程:
1.预处理pre-processing -E
这阶段输入.c/.C:主要处理源文件中的#ifdef #include #define预处理命令,生成一个中间文件.i
gcc -E test.c -o test.i
2.编译 compiling -S
输入的中间文件是.i,编译后生成汇编语言.s
gcc -S test.i -o test.s
3.汇编 Assembling -c
将汇编文件test.s 转换成二进制机器代码.o
gcc -c test.s -o test.o
4.链接 Linking
生成可执行文件
gcc test.c -o test
压缩
tar -czvf test.tar.gz test*
解压
tar -xzvf test.tar.gz
gcc -o test testname.c other1.c other2.c
-g 产生调试gdb所必需的符号信息
-O/-O2 优化
-Wall 输出警告
-w 关闭警告
-Ldirname : 加到程序库文件搜索 默认:/usr/lib
-lname : 链接库 -lm表libm.a,在-L指定目录下
gcc test.c -o test -L/usr/lib -lm
==================调试器 gdb===============================
调试可执行文件
如果使一个可执行文件被gdb调试,那么使用gcc时需要加入-g选项。
gcc -g test.c -o test
gdb test
显示源代码
list : 显示10行
list 5,10 :显示5-10行
list get_sum : 显示get_sum函数代码
如果在调试中要运行linux命令,可以在gdb提示符下输入shell命令
shell ls
查找
search 字符串
forward 字符串
reverse-search 字符串
执行程序
run
获得帮助
help list
help all
设置管理断点
以行号设置断点
break 7
以函数名设置断点
break get_sum
以条件表达式断点
break 行号/函数名 if 条件
整个过程运行当条件表达式的值发生变发
watch 条件表达式
watch i==99
删除断点
clear 6
继续运行
contiune
打印变量i值
print i
print sum
下一步
next
查看当前中断点
info breakpoints
使中断失效
disable 2
删除断点
clear 行号/函数名/断点
delete num
查看设置变量值
print 变量
print 变量=值
whatis 变量:查看变量类型
变量赋值
set variable 变量=值
控制程序运行
continue
kill
next
step
================make 使用和makefile编写====================
有一个用来维护程序模块关系和生成可执行程序的工具make
它可以根据程序模块的修改情况重新编译链接生成中间代码或最终的可执行文件
执行make命令,需要一个名为Makefile /makefile文本文件
它定义了模块间的依赖关系,指定文件的编译顺序,以及编译所使用的命令。
make从Makefile文件中获取模块间的依赖关系,判断哪些文件过时了,根据这些信息make确定哪些文件需要重新
编译,然后使用Makefile中的编译命令进行编译。
Makefile
main:main.o module1.o module2.o
gcc main.o module1.o module2.o -o main
main.o:main.c head1.h head2.h common_head.h
gcc -c main.c
module1.o: module1.c head1.h
gcc -c module1.c
module2.o: module2.c head2.h
gcc -c module2.c
Makefile基本构成
一条规则指定一个或多个目标文件,目标文件后面跟的是编译生成该目标所依赖的文件或模块,
最后是生成或更新目票文件所使用的命令。
目标文件列表 分隔符 依赖文件列表 [;命令]
[命令]
[命令]
make如何解释执行Makefile
make
gcc -c main.c
gcc -c module1.c
gcc -c module2.c
gcc main.o module1.o module2.o -o main
make -f othername
make --file=othername
Makefile文件的构成
显式规则
隐含规则
使用变量
文件指示
注释
module1.o : head1.h
等价于
module1.o : module1.c head1.h
gcc -c module1.c -o module1.o
main : main.o module1.o module2.o
gcc main.o module1.o module2.o -o main
main.o:head1.h head2.h common_head.h
module1.o:head1.h
module2.o:head2.h
$表示使用变量或调用函数
规则的主要思想:目标文件的内容由依赖文件决定,依赖文件的任何一处
改动,将导致目前已经存在的目标文件的过时。
foo : foo.c | somelib
gcc -o foo foo.c somelib
| 前面的文件是普通依赖文件,如果foo.c过时,将导致foo重新生成。
而 | 后面的文件过时,foo 不会被重新生成,也就是第二行命令不会执行。
一条规则中可以有一个或多个命令行,以Tab开头,后加+ - @再写命令
- 执行命令时遇到错误,继续执行不退出make
+ 本行命令始终被执行
@ 执行本行命令时不在屏幕上打印内容
file.o: file.c head1.h head2.h
-mv file.o /tmp
gcc -c file.c
clean:
-rm -f *.o
make clean
all : program1 program2 program3
.PHONY : all
program1: program1.c utils.h
gcc -o program1 program1.c
program2: program2.c
gcc -o program2 program2.c
program3: program3.c comm.h utils.h
gcc -o program3 program3.c
含多个目标规则
module1.o module2.o module3.o : command.h
相当于
modlue1.o : module1.c command.h
gcc -c module1.c -o comdule1.o
modlue2.o : module2.c command.h
gcc -c module2.c -o comdule2.o
modlue3.o : module3.c command.h
gcc -c module3.c -o comdule3.o
搜索目录
VPATH指定依赖
VPATH=/usr/src:../headers
使用变量
变量名 赋值符 变量值
赋值符
= := += ?=
系统变量
$@
$?
$<
$*
引用变量
$(变量名)
${变量名}
定义变量
= 赋值变量递归展开变量
:= 赋值的变量是立即展开变量
foo = $(bar)
bar = $(ugh)
ugh = Huh
all :
echo $(foo)
x := foo
y := $(x) bar
x := later
?= 只有此变量在之前没有赋值情况下会对这个变量赋值
FOO ?= bar
objects = main.o foo.o bar.o utils.o
objects += another.o
预定义变量
CC = cc
CFLAGS = -o
MAKE = make
module1.o : module1.c head1.h
$(CC) -c modlue1.c
自动变量
$@ 表示一个规则中的目标文件
file1.o file2.o : header.h
cp $@ /backup
file1.o : file1.c header.h
cp $@ /backup
gcc -c file1.c -o file1.o
file2.o : file2.c header.h
cp $@ /backup
gcc -c file2.c -o file2.o
$% 当规则的目标文件是一个静态库文件时,表一个成员名
foo.a $%表foo.a
$< 第一个依赖文件名
file1.o file2.o : header.h
cp $@ /backup
$> 库名
$? 所有目标文件新的依赖列表,以空格分开
$^ 所有依赖文件列表,不重复
$+ 所有依赖文件列表,可重复
$* 目标文件去掉后缀后的名称
file1.o file2.o : header.h
gcc -c $*.c -o $@
$(CC) $(CFLAGS) $@ $<
库中成员
库名(成员名1 成员2)
库名(成员1) 库名(成员2)
mylib.a(file.o)
表示静态库mylib.a(以.so结尾的是动态库)中有一个名为file.o的文件
建立和维护一个库时,将库名作为目标名,把希望放到库的文件作依赖文件
mylib.a : mylib(file1.o) mylib(file2.o) mylib(file3.o)
mylib.a : mylib(file1.o file2.o file3.o)
ar -ruv 库名 目标文件名
mylib : mylib(file1.o)
gcc -c file1.c
ar -ruv mylib file1.o
rm -f file1.o
mylib:mylib(file2.o)
gcc -c file2.c
ar -ruv mylib file2.o
rm -f file2.o
mylib:mylib(file1.o file2.o file3.o)
ar -ruv $@ $?
rm -f $?
file1.o file2.o file3.o :
========================================================
转载于http://blog.csdn.net/luoying198791/article/details/20715499