gcc使用举例 源程序:gcctest.c #include <stdio.h> int main(void){ int i,j; i=0;j0: i=j+1; printf(“Hello Wor1d!\n”): printf(“i=jtl=%dn”,i); ●编译和运行 gcc -o gcctest gcctest.c ./gcctest 4口4四1是14P刀00 陈香兰(xlanchenoustc,edu.cn)(升异轧应 长人式样作系统 November28,201414/111
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gcc使用举例 . 源程序:gcctest.c . . #include <stdio.h> int main(void) { int i,j; i=0;j=0; i=j+1; printf(“Hello World!\n”); printf(“i=j+1=%d\n”,i); } 编译和运行 gcc − o gcctest gcctest.c ./gcctest 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 28, 2014 14 / 111
gcc的工作过程 。如果使用-ⅴ选项,则可以看到许多被隐藏的信息。例如 gcc -o gcctest gcctest.c-v 1口t4四1是142刀00 陈香兰(xlanchenoustc,edu,cn)(升界款应 长人式操作香统 Novesber28,201415/111
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gcc的工作过程 如果使用-v选项,则可以看到许多被隐藏的信息。例如 gcc -o gcctest gcctest.c -v 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 28, 2014 15 / 111
gcc的编译过程 。一般情况下,c程序的编译过程为 ○预处理 ©编译成汇编代码 ©汇编成目标代码 Q链接 1口4四1是4P刀00 陈香兰(xlanchenoustc,edu,cn)(升界款应 长人式操作香统 Novesber28.201416/111
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gcc的编译过程 一般情况下,c程序的编译过程为 1. 预处理 2. 编译成汇编代码 3. 汇编成目标代码 4. 链接 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 28, 2014 16 / 111
1、预处理 。预处理:使用-E参数 输出文件的后缀为“.cpp” gcc -E -o gcctest.cpp gcctest.c 。使用wC命令比较预处理后的文件与源文件,可以看到 两个文件的差异 wc命令:wc gcctest.c gcctest.cpp 812 117 gcctest.c 851 2096 17605 gcctest.cpp 859210817722总用量 4口4四是4P在刀0C 陈香兰(xlanchenoustc,ed加.cn)(计年丸应 长人式样饰泰统 November28,201417/111
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1、预处理 预处理:使用-E参数 输出文件的后缀为“.cpp” gcc -E -o gcctest.cpp gcctest.c 使用wc命令比较预处理后的文件与源文件,可以看到 两个文件的差异 . wc命令:wc gcctest.c gcctest.cpp . . 8 12 117 gcctest.c 851 2096 17605 gcctest.cpp 859 2108 17722 总用量 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 28, 2014 17 / 111
关于wC命令 wc一help 用法:wc[选项]..[文件].· 或:wc[选项]..一fi1es0-from=F Print newline,word,and byte counts for each FILE,and a total line if more than one FILE is specified.With no FILE,or when FILE is-,read standard input.A word is a non-zero-length sequence of characters delimited by white space. The options below may be used to select which counts are printed,always in the following order:newline,word,character,byte,maximum line length. -c,-bytes print the byte counts -m,-chars print the character counts -1,-lines print the newline counts -fi1es0-from=文件 从指定文件读取以NUL终止的名称,如果该文件被 指定为”-”则从标准输入读文件名 -L, 一max-1ine-1 ength 显示最长行的长度 -w,一words 显示单词计数 -help 显示此帮助信息并退出 -version 显示版本信息并退出 陈香兰(xlanchenoustc,edu,cn) (计异机应 长人式操炸系战 November 28.2014 18/111
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 关于wc命令 . wc –help . . 用法:wc [选项]... [文件]... 或:wc [选项]... –files0-from=F Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. A word is a non-zero-length sequence of characters delimited by white space. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length. -c, –bytes print the byte counts -m, –chars print the character counts -l, –lines print the newline counts –files0-from=文件 从指定文件读取以NUL 终止的名称,如果该文件被 指定为”-”则从标准输入读文件名 -L, –max-line-length 显示最长行的长度 -w, –words 显示单词计数 –help 显示此帮助信息并退出 –version 显示版本信息并退出 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 28, 2014 18 / 111