中国高校课件下载中心 》 教学资源 》 大学文库

安徽理工大学:《Linux开发基础 Development Foundation on Linux OS》课程教学资源(PPT课件讲稿)Section 2、3 GNU C/C++编程(CGI programming in GNU C/C++ language)

文档信息
资源类别:文库
文档格式:PPT
文档页数:75
文件大小:554KB
团购合买:点击进入团购
内容简介
安徽理工大学:《Linux开发基础 Development Foundation on Linux OS》课程教学资源(PPT课件讲稿)Section 2、3 GNU C/C++编程(CGI programming in GNU C/C++ language)
刷新页面文档预览

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY Section 2 GNU C/C++programming 3

3 Section 2 GNU C/C++ programming

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY What is GNU? The GNU operating system is a complete free software system,upward-compatible with Unix.GNU stands for "GNU's Not Unix".Richard Stallman made the Initial Announcement of the GNU Project in September 1983. Source: http://www.gnu.org/gnu/initial- announcement.html 4

4 What is GNU? ➢ The GNU operating system is a complete free software system, upward-compatible with Unix. GNU stands for “GNU's Not Unix”. Richard Stallman made the Initial Announcement of the GNU Project in September 1983. Source: http://www.gnu.org/gnu/initial￾announcement.html

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY What is Free Software? > "Free software"is a matter of liberty,not price.To understand the concept,you should think of "free"as in "free speech",not as in "free beer". > Free software is a matter of the users'freedom to run,copy, distribute,study,change and improve the software.More precisely, it refers to four kinds of freedom,for the users of the software: The freedom to run the program,for any purpose (freedom O). The freedom to study how the program works,and adapt it to your needs(freedom 1).Access to the source code is a precondition for this. The freedom to redistribute copies so you can help your neighbor (freedom 2). ▣ The freedom to improve the program,and release your improvements to the public,so that the whole community benefits (freedom 3).Access to the source code is a precondition for this. 5

5 What is Free Software? ➢ “Free software” is a matter of liberty, not price. To understand the concept, you should think of “free” as in “free speech”, not as in “free beer”. ➢ Free software is a matter of the users' freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:  The freedom to run the program, for any purpose (freedom 0).  The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.  The freedom to redistribute copies so you can help your neighbor (freedom 2).  The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY What is gcc? >GCC,the GNU Compiler Collection. >The GNU Compiler Collection includes front ends for C,C++,Objective-C,Fortran,Java, and Ada,as well as libraries for these languages (libstdc++,libgcj,...).GCC was originally written as the compiler for the GNU operating system.The GNU system was developed to be 100%free software,free in the sense that it respects the user's freedom. Source:http://gcc.gnu.org 6

6 What is gcc? ➢ GCC, the GNU Compiler Collection. ➢ The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...). GCC was originally written as the compiler for the GNU operating system. The GNU system was developed to be 100% free software, free in the sense that it respects the user's freedom. Source: http://gcc.gnu.org

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 2.1GNUC/C++编译器的使用 gcc通过扩展名来判断文件的类型,从而确定用何种方式处理该文件 后缀名 说明 .c C语言源代码文件 .C/.cc/.cxx C++源代码文件 .h 程序所包含的头文件 i 已经预处理过的C语言源代码文件 .ii 已经预处理过的C++源代码文件 .m Objective-C语言源代码文件 .S 汇编语言源代码文件 .S 经过预编译的汇编语言源代码文件 .a/.so 编译后的库代码 .0 编译后的目标文件

7 后缀名 说明 .c C语言源代码文件 .C/.cc/.cxx C++源代码文件 .h 程序所包含的头文件 .i 已经预处理过的C语言源代码文件 .ii 已经预处理过的C++源代码文件 .m Objective-C语言源代码文件 .s 汇编语言源代码文件 .S 经过预编译的汇编语言源代码文件 .a/.so 编译后的库代码 .o 编译后的目标文件 2.1 GNU C/C++编译器的使用 gcc通过扩展名来判断文件的类型,从而确定用何种方式处理该文件

安藏理工大坚 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 2.1GNUC/C++编译器的使用 gcc编译器选项和参数 参数 含义 -o Place the output into -c Compile and assemble,but do not link -ggdb Produce debugging information for use by GDB. -0 the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of com-pilation time. -9 Produce debugging information in the operating system's native format.GDB can work with this debugging information. -I Add the directory dir to the list of directories to be searched for header files.Directories named by-I are searched before the -L Search the library named library when linking 8

8 2.1 GNU C/C++编译器的使用 gcc 编译器选项和参数 参数 含义 -o Place the output into -c Compile and assemble, but do not link -ggdb Produce debugging information for use by GDB. -O the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of com-pilation time. -g Produce debugging information in the operating system's native format. GDB can work with this debugging information. -I Add the directory dir to the list of directories to be searched for header files. Directories named by -I are searched before the -L Search the library named library when linking

安藏理工大學 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY 2.1GNUC/C++编译器的使用 1、直接通过编译生成目标代码可执行文件: $gcc hello.c -o hello 2、如果一个程序包含有多个源文件,则也可直接生成目标代码: void f1() f printf“y%sln”,"function1")月 } void f2() { printf("%sIn","function 2"); main() { 10; 20时 } $gcc f1.c f2.c main.c -o main 9

9 2.1 GNU C/C++编译器的使用 1、直接通过编译生成目标代码可执行文件: $gcc hello.c –o hello 2、如果一个程序包含有多个源文件,则也可直接生成目标代码: void f1() { printf(“%s\n”, "function 1"); } void f2() { printf("%s\n", "function 2"); } main() { f1(); f2(); } $gcc f1.c f2.c main.c –o main

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY > Linux.上广泛使用的C语言编译器是GNUC编译器,GNU C建立在自由软件基金会的编程许可证的基础上,可以自 由发布。在Liux下,一个完整的C语言开发环境到少包 括以下三个组成部分 √函数库glibc(在/usr/八ib和/ib目录中) √ 编译器gcc √ 系统头文件glibc_header(*.h) >gbc是构成一个完整的C语言开发环境所必不可少的组成 部分,也是Linux下C语言的主要函数库。 > glibc headerr中包含了系统编译源代码所需要的声明文 件,如果缺少系统头文件,很多用到系统功能的C程序将无 法编译。(包含在/usr/include/及其子目录中) 10

10 ➢ Linux上广泛使用的C语言编译器是GNU C编译器,GNU C建立在自由软件基金会的编程许可证的基础上,可以自 由发布。在Linux下,一个完整的C语言开发环境到少包 括以下三个组成部分: ✓函数库glibc (在/usr/lib和/lib目录中) ✓编译器gcc ✓系统头文件glibc_header (*.h) ➢ glibc是构成一个完整的C语言开发环境所必不可少的组成 部分,也是Linux下C语言的主要函数库。 ➢ glibc_header中包含了系统编译源代码所需要的声明文 件,如果缺少系统头文件,很多用到系统功能的C程序将无 法编译。(包含在/usr/include/及其子目录中)

安藏理工大学 ANHUI UNIVERSTTY OF SCIENCE TECHNOLOGY 2.2 GNUC/C+函数库 定义:是一些预先编译好的函数的集合,那些函数都是按照可再使用 的原则编写的。它们通常是一组相互关联的用来完成某项常见工作的 函数构成(比如c库里面的标准输入输出函数、时间函数和数学函数 等)。 >函数库中的函数可以通过连接程序与应用程序进行连接,而不必在每 次开发程序时都对这些通用的函数进行编译。 不同类型的应用程序将会使用不同的函数库。如数学应用将使用数学 库libm(/usr/ib/Iibm.a,/usr/Iib/ibm.so),标准的C库 libc(/usr/lib/libc.a,/usr/lib/libc.so). 注意:*.h只是对函数的声明(declaration),函数的定义是在具体的函 数库中 11

11 2.2 GNU C/C++函数库 ➢ 定义:是一些预先编译好的函数的集合,那些函数都是按照可再使用 的原则编写的。它们通常是一组相互关联的用来完成某项常见工作的 函数构成(比如c库里面的标准输入输出函数、时间函数和数学函数 等)。 ➢ 函数库中的函数可以通过连接程序与应用程序进行连接,而不必在每 次开发程序时都对这些通用的函数进行编译。 ➢ 不同类型的应用程序将会使用不同的函数库。如数学应用将使用数学 库libm(/usr/lib/libm.a, /usr/lib/libm.so),标准的C库 libc(/usr/lib/libc.a,/usr/lib/libc.so)。 注意:*.h只是对函数的声明(declaration),函数的定义是在具体的函 数库中

安藏理工大学 ANHUI UNIVERSITY OF SCIENCE TECHNOLOGY > 所有的程序都将使用标准的C函数库bc,该库中包含了内存管理或 输入输出操作的基本函数,这些库都存放在/usr/b或/ib这些系统 公用的目录中,系统中的任何用户都可以利用这些库。 注:用户可以自己定义自己的函数库! 库可以有三种使用的形式: 静态库(*.):代码在编译时就已连接到开发人员开发的应用程序 中。静态库在程序编译时会被连接到目标代码中,程序运行时将 不再需要该静态库 1 共享库(shared object,以*.so作为后缀):只是在程序开始运行 时才载入,在编译时,只是简单地指定需要使用的库函数。 动态库:是共享库的另一种变化形式,也是在程序运行时载入 使用的库函数不是在程序运行开始,而是在程序中的语句需要使 用该函数时才载入。类似于windows OS中的DLL文件。 12

12 ➢ 所有的程序都将使用标准的C函数库libc,该库中包含了内存管理或 输入输出操作的基本函数,这些库都存放在/usr/lib或/lib这些系统 公用的目录中,系统中的任何用户都可以利用这些库。 注:用户可以自己定义自己的函数库! ➢ 库可以有三种使用的形式: ✓ 静态库(*.a):代码在编译时就已连接到开发人员开发的应用程序 中。静态库在程序编译时会被连接到目标代码中,程序运行时将 不再需要该静态库 ✓ 共享库(shared object,以*.so作为后缀):只是在程序开始运行 时才载入,在编译时,只是简单地指定需要使用的库函数。 ✓ 动态库:是共享库的另一种变化形式,也是在程序运行时载入, 使用的库函数不是在程序运行开始,而是在程序中的语句需要使 用该函数时才载入。类似于windows OS中的DLL文件

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档