linux programming introducation

50 159 0
linux programming introducation

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TMA Training Center (www.ttc.edu.com) Slide # 1 Linux Programming Introduction TMA Training Center (TTC) TMA Training Center (TTC) TMA Training Center (www.ttc.edu.com) Slide # 2 Contents  Overview  GNU Compiler  GNU Make (MAKE)  GNU Debugger (GDB)  Programming with Emacs  Using Libraries TMA Training Center (www.ttc.edu.com) Slide # 3 Objectives  Understanding of development tools for Linux  How to use GNU tools  How to use an IDE  Using library TMA Training Center (www.ttc.edu.com) Slide # 4 Overview  Linux and Linux Distributions People usually understand Linux to be an entire package of developer tools, editors, GUIs, networking tools, and so forth. More formally, such packages are called distributions such as Red Hat, SuSE, Mandrake, and Caldera. Linux itself is the core of the operating system: the kernel. The kernel is the program acting as Chief of Operations. It is responsible for such tasks as handling requests for memory, accessing disks, and managing network connections TMA Training Center (www.ttc.edu.com) Slide # 5 Overview (cont.)  Free software and GNU license The concept of free software was with the initial distributions of UNIX from Bell Labs. The most important thing to emerge from the GNU project has been the GNU General Public License (GPL). This license explicitly states that the software being released is free, and that no one can ever take away these freedoms. It is acceptable to take the software and resell it, even for a profit; however, in this resale, the seller must release the full source code, including any changes. Because the resold package remains under the GPL, the package can be distributed free and resold yet again by anyone else for a profit TMA Training Center (www.ttc.edu.com) Slide # 6 Overview (cont.)  GNU and Linux • Linux, author of the kernel, is the program that performs the most basic functions of an operating system: It controls and interfaces with the computer's hardware, handles allocation of memory and other resources, allows multiple programs to run at the same time, manages the file system, and so on. • The Linux kernel and other software, programs and libraries developed as part of the GNU Project, has proven to be a powerful combination. Although the combination is often called "Linux" for short, the complete system couldn't work without GNU software, any more than it could operate without the kernel. TMA Training Center (www.ttc.edu.com) Slide # 7 GNU Tools  Example:  C source file - main.c #include <stdio.h> #include “reciprocal.h” int main() { const int i = 2; printf (“The reciprocal of %d is %g\n”, i, reciprocal (i)); return 0; } TMA Training Center (www.ttc.edu.com) Slide # 8 GNU Tools  Header file - reciprocal.h /** * reciprocal.h - define reciprocal function * */ double reciprocal (int i);  C source file - reciprocal.c #include “reciprocal.h” double reciprocal (int i) { return 1.0/i; } TMA Training Center (www.ttc.edu.com) Slide # 9 GNU Tools  GNU Compiler Collection (GCC)  The name of the C compiler is gcc and the C++ compiler is called g++  Syntax:  gcc [option | filename]…  g++ [option | filename]…  Options:  -c: compile source code to object file  -I: tell compiler where to search for header files  -o: Specify output filename  -l[library]: link in another library  -L[path]: want the linker to search other directions  -O2: want to have gcc optimize the code so that it runs as quickly as possible TMA Training Center (www.ttc.edu.com) Slide # 10 GNU Tools  Example:  Compile C source file gcc -c main.c (main.o) gcc -c reciprocal.c (reciprocal.o)  With a header file “hello.h” in directory “/tmp/inc” gcc -c -I /tmp/inc reciprocal.c (reciprocal.o)  Use gcc to link object file (s) gcc –o reciprocal main.o reciprocal.o (reciprocal)  With another library (the library is in standard places) gcc -o reciprocal main.o reciprocal.o -lpam (reciprocal)  With another library (the library is in directory “/tmp/lib”) gcc -o reciprocal main.o reciprocal.o -L/tmp/lib -lpam (reciprocal)  Now you can run reciprocal like this ./reciprocal [...]... /usr/include/asm, and /usr/include /linux Source Code   Linux distribution includes full source code for the entire system and all programs included with it Source code of Linux kernel: /usr/src /linux TMA Training Center (www.ttc.edu.com) Slide # 21 Programming with Emacs  Emacs   Emacs (editing macros) written by Stallman provides a rich, highly configuratable programming enviroment The world is... Emacs People who prefer Vi Everyone else (kdevelop, eclipse,…) TMA Training Center (www.ttc.edu.com) Slide # 22 Programming with Emacs  Starting and Stopping Emacs  To start Emacs, type: emacs or emacs filename  To exit of Emacs, type Ctrl-x TMA Training Center (www.ttc.edu.com) Slide # 23 Programming with Emacs  Moving Around           M-b: Moves the cursor to the beginning of the word... C-v: Moves display down one screen full M-v: Moves display up one screen full TMA Training Center (www.ttc.edu.com) Slide # 24 Programming with Emacs  Search and Replace  Type C-s, the minibuffer prompts for a search string TMA Training Center (www.ttc.edu.com) Slide # 25 Programming with Emacs     Type the string, Emacs moves the cursor to the first occurrence For the next occurrence, type C-s... type to “visit” the file, type the filename in the minibuffer, and press Enter TMA Training Center (www.ttc.edu.com) Slide # 26 Programming with Emacs  Multiple Windows  C-x 2: it splits the current window into two windows TMA Training Center (www.ttc.edu.com) Slide # 27 Programming with Emacs         C-x o: Move to the other window C-M-v: Scroll the other window C-x 0: Delete the current... (www.ttc.edu.com) Slide # 28 Programming with Emacs  Compilation Using Emacs  M-x compile: compiles code using, by default, make -k  Example: you are working on a file named rdline.c, type M-x compile to compile it Then type rdline.o TMA Training Center (www.ttc.edu.com) Slide # 29 Using Libraries  Library Tools   Take a quick tour of the tools to create, maintain and manage programming libraries nm... /usr/bin/mutt libnsl.so.1 => /lib/libnsl.so.1 (0x40019000) libslang.so.1 => /usr/lib/libslang.so.1 (0x4002e000) libm.so.6 => /lib/libm.so.6 (0x40072000) libc.so.6 => /lib/libc.so.6 (0x4008f000) /lib/ld -linux. so.2 => /lib/ld -linux. so.2 (0x40000000) → The execute file mutt needs five shared libraries TMA Training Center (www.ttc.edu.com) Slide # 32 Using Libraries  Static Library  Dynamic Library - Attach to compiled... -O2 -c main.c gcc -O2 -c reciprocal.c gcc -O2 -o reciprocal main.o reciprocal.o TMA Training Center (www.ttc.edu.com) Slide # 15 GNU Tools  GNU Debugger (GDB)  GDB:    Is the debugger used by most Linux programmers to figure out why the program doesn’t work as you think Use GDB to step through your code, set breakpoints, and examine the value of local variables Usage:  Must compile with Debugging... (gdb) run Step over the reciprocal function: (gdb) next Step into the reciprocal function: (gdb) step Quit gdb: (gdb) quit TMA Training Center (www.ttc.edu.com) Slide # 18 Finding Info  Man Pages   Linux distributions include man pages for most standard commands, system calls, and standard library functions They are divided into numbered sections; for programmers, the most important are these: ... commands Eg: man 8 signal TMA Training Center (www.ttc.edu.com) Slide # 19 Finding Info  Info   The Info documentation system contains more detailed documentation for many core components of the GNU /Linux system, plus several other programs Among the most useful Info documents are these:       gcc - The gcc compiler libc - The GNU C library, including many system calls gdb - The GNU debugger . library TMA Training Center (www.ttc.edu.com) Slide # 4 Overview  Linux and Linux Distributions People usually understand Linux to be an entire package of developer tools, editors, GUIs, networking. (MAKE)  GNU Debugger (GDB)  Programming with Emacs  Using Libraries TMA Training Center (www.ttc.edu.com) Slide # 3 Objectives  Understanding of development tools for Linux  How to use GNU tools  How. TMA Training Center (www.ttc.edu.com) Slide # 1 Linux Programming Introduction TMA Training Center (TTC) TMA Training Center (TTC) TMA Training Center

Ngày đăng: 04/07/2014, 21:51

Mục lục

  • Linux Programming Introduction

  • Contents

  • Objectives

  • Overview

  • Overview (cont.)

  • Slide 6

  • GNU Tools

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • Slide 13

  • Slide 14

  • Slide 15

  • Slide 16

  • Slide 17

  • Slide 18

  • Finding Info

  • Slide 20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan