1 / 21

Linux Programming Prerequisite

Jianjian SONG Software Institute, Nanjing University Sept. 2004. Linux Programming Prerequisite. Contents. Overview of Linux Programming Using gcc & gdb Make & Makefile. Programming Language. High-level Language C/C++, Java, Fortran… ELF binary format Excutable and Linkable Format

Download Presentation

Linux Programming Prerequisite

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jianjian SONG Software Institute, Nanjing University Sept. 2004 Linux Programming Prerequisite

  2. Contents Overview of Linux Programming Using gcc & gdb Make & Makefile

  3. Programming Language High-level Language C/C++, Java, Fortran… ELF binary format Excutable and Linkable Format 工具接口标准委员会(TIS)选择了正在发展中的ELF体系上不同操作系统之间可移植的二进制文件格式 Script Shell: sh/bash, csh, ksh Perl, Python, tcl/tk, sed, awk…

  4. Development Tools GCC GNU C Compiler -> GNU Compiler Collection The gcc command: Front end GDB GNU Debugger The gdb command xxdgb, ddd… Binary utilities as, ld, ar, ldd… Make

  5. Workbench • IDE • Emacs/xemacs • Kdevelop • Eclipse • Kylix3 • Command line • Editor: vi/vim/gvim, emacs/xemacs, pico • Source Reader: source navigator; vi/emacs+ ctags/etags • Configure Tools: automake, autoconf, m4

  6. A User’s Viewpoint 用户 用户 用户 用户 Shell 核外程序 高级语言和实用程序 系统调用 进程间通信 文件子系统 进程 管理 子系统 调度程序 内核 高速缓存 存储管理 块设备 字符设备 设备驱动程序 硬 件 控 制 硬 件

  7. A C Programmer’s Viewpoint

  8. System Calls and Libraries 系统调用 Linux内核的对外接口;用户程序和内核之间唯一的接口 函数库 依赖于系统调用 一般来说,标准函数库建立在系统调用的上层,提供的功能比系统调用强,使用也比较方便。 例:标准I/O库

  9. Libraries and Head Files • Static Libraries (.a files) • Lab (gcc + ar) • Dynamic Libraries/Shared Objects (.so files) • Lab (gcc)

  10. GCC GCC: GNU C Compiler -> GNU Compiler Collection http://gcc.gnu.org Front ends and back ends Front ends: gcc, g++, gcj, g77, gnat Back ends: support various target 4 stages of gcc Preprocessing (cpp command) Compilation Assembly (as command) Linking (ld command)

  11. File Name Suffix (1) .c C source code which must be preprocessed .i C source code which should not be preprocessed .cc .cp .cpp .CPP.c++ .C .cxx C++ source code which must be preprocessed .ii C++ source code which should not be preprocessed .h C or C++ header file to be turned into a precompiled header .H .hh C++ header file to be turned into a precompiled header .s Assembler code .S Assembler code which must be preprocessed

  12. File Name Suffix (2) .o Object file .a Static library file (archive file) .so Dynamic library file (shared object)

  13. GCC options (1) Usage: gcc [options] [filename] Basic options: -E: 只对源程序进行预处理(调用cpp预处理器) -S: 只对源程序进行预处理、编译 -c: 执行预处理、编译、汇编而不链接 -o output_file: 指定输出文件名 -g: 产生调试工具必需的符号信息 -O/On: 在程序编译、链接过程中进行优化处理 -Wall: 显示所有的警告信息

  14. GCC options (2) Basic options: -Idir: 指定额外的头文件搜索路径 -isystem dir -Ldir: 指定额外的库文件搜索路径 -lname: 链接时搜索指定的库文件 -DMACRO[=DEFN]: 定义MACRO宏

  15. GDB GDB: GNU Debug 设置断点 监视变量值 单步执行 修改变量值

  16. gdb commands file 打开要调试的文件 break/tbreak 设置断点,可以是行号、函数名及地址(以*开头) tbreak: 设置临时断点 run 执行当前调试的程序 list 列出源代码的一部分 next 执行一条语句但不进入函数内部 step 执行一条语句,是函数则进入函数内部 display 显示表达式的值 print 临时显示表达式的值 kill 中止正在调试的程序 quit 推出gdb shell 不退出gdb就执行shell命令 make 不退出gdb就执行make

  17. Quiz 从标准输入(stdin/cin)输入10个(或n个, n不定)整数,排序后打印到标准输出。 C/C++均可 注明采用的数据结构、排序算法

  18. make & makefile Multi-file project IDE make make & makefile makefile描述模块间的依赖关系; make命令根据makefile对程序进行管理和维护;make判断被维护文件的时序关系

  19. Makefile Makefile: Dependency(target, prerequisites) Rule(command(s)) Example:

  20. make make [-f filename] [targetname] Targets A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as 'clean' (phony target).

  21. makefile extensions Makefile extensions macros/variables implicit/suffix rules subdirectories archive Using "info make"

More Related