Linux下运行C程序
一、Linux下执行C程序
分步编译
1.预处理:cpp(gcc -E) first.c -o first.i
2.汇编:gcc -S first.i -o first.s
3.编译成机器语言:as(gcc -c) first.s -o first.o
4.链接:gcc first.o -o first.out
5.运行:./first.out
一步编译
1.直接将.c文件编译成.out文件:gcc first.c -o first.out
2.运行:./first.out
------------------------------------------------------ 注意:./执行.out文件,中间不能有空格
-o后面指明输出的文件(可以带上目录)
二、Linux下C程序的常用操作
sudo cp first.out /bin ---将C程序变成命令
grep “printf” first.i ---在first.i中查找printf
帮助:man 1 ls 帮助
man 2 系统调用
man 3 库函数
三、C的一般规定
1.预处理命令:所有以#开头的命令都是预处理命令,它不是C语句作用:将指定路径下的文件(如:stdio.h)拷贝到当前程序中
2.注释风格:/* */