学习linux programming(1)

【1. linux applications 有两种形式】
  i)可执行的文件: 可由计算机直接运行,相当于windows的.exe文件
  ii)Script: collections of instructions for another program. 相当于windows的.bat .cmd文件

 

【2. PATH】

在Linux中,当输入程序名(如Firefox)时,系统会在名为PATH的Shell变量所给定的一系列目录中寻找是否有同名的文件。
  查看PATH的值,在Linux: $PATH 或者 echo $PATH
                windows: PATH

Linux可执行文件位置说明:
/bin: binaries, programs used in booting the system
/usr/bin: user binaries, standard programs available to users
/usr/local/bin:  local binaries, programs specific to an installation
当以administator身份进入时,可能会使用系统管理程序所在的PATH目录,如: /sbin 或 /usr/sbin

Linux,like unix, 在PATH变量的entries之间用colon(:)分隔,而windows和ms-dos用semicolon (;) 分隔。
Linux:使用forward slash (/) 来分隔目录
eg: /usr/bin/
windows: 使用backward slash (/)来分隔
eg: c:/Documents and settings/user>

 

【3. C compiler】
在POSIX-compliant system  (POSIX: Portable Operating System Interface), C compiler is called c89.
in linux, c89, cc, gcc refer to the system c compiler.

 

【4. first c program in linux】
 1) hello.c file content

 

 

 2) compile
  $gcc -o hello hello.c


 gcc参数说明:
  -o <file>:输出到file,若未指定-o,则default输出到a.out
 如果要查看中间生成文件,可用gcc参数  -save-temps
  $gcc -save-temps -o hello hello.c
  $ls
  hello hello.c hello.i hello.o hello.s
  //以上生成的4个文件说明见【5.编译系统】
 3) execute
  $./hello


 说明:
 若直接用hello,即执行
 $hello
 则系统会在Shell变量PATH所列出的目录中search,若恰好有一个名为

hello的文件,则执行之。
 ./: 代表当前目录。

 

【5.编译系统】

  编译系统

预处理阶段

   预处理器(cpp)根据以字符#开头的命令(directive),修改原始的C程序。比如hello.c中的第一行的#include<stdio.h>指令告诉预处理器读取系统头文件stdio.h的内容,并把它直接插入到程序文本中去。结果就得到了另一个C程序,通常是以.i作为文件扩展名。

 

编译阶段

   编译器(ccl)将文本文件hello.i翻译成文本文件hello.s,它包含一个汇编语言程序。汇编语言程序中的每条语句都以一种标准的文本格式确切地描述了一条低级机器语言指令。

 

汇编阶段

   汇编器(as)将hello.s翻译成机器语言指令,把这些指令打包成为一种叫做可重定位(relocatable)目标程序的格式,并将结果保存在目标文件hello.o中。hello.o文件是一个二进制文件,它的字节编码是极其语言指令而不是字符,如果我们在文本编辑器中打开hello.o文件,呈现的将是一堆乱码。

 

链接阶段

   我们的hello程序调用了printf函数,它是标准c库中的一个函数,每个C编译器都提供。printf函数存在于一个名为printf.o的单独的预编译目标文件中,而这个文件必须以某种方式并入到我们的hello.o程序中。链接器(ld)就负责处理这种并入,结果就得到hello文件,它是一个可执行目标文件,可执行文件加载到存储器后,由系统负责执行。

 

 

 

 

xv Contents Graphical Debugging Tools 299 DDD 299 Eclipse 302 Kernel Debugging 305 Don’t Panic! 306 Making Sense of an oops 307 Using UML for Debugging 309 An Anecdotal Word 312 A Note about In-Kernel Debuggers 313 Summary 313 Chapter 11: The GNOME Developer Platform 315 GNOME Libraries 316 Glib 316 GObject 316 Cairo 316 GDK 317 Pango 317 GTK+ 317 libglade 318 GConf 318 GStreamer 318 Building a Music Player 319 Requirements 319 Getting Started: The Main Window 319 Building the GUI 321 Summary 340 Chapter 12: The FreeDesktop Project 341 D-BUS: The Desktop Bus 341 What Is D-Bus? 342 Under D-Hood of D-Bus 342 D-Bus Methods 346 Hardware Abstraction Layer 350 Making Hardware Just Work 350 Hal Device Objects 353 The Network Manager 358 Other Freedesktop Projects 360 Summary 360 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xv xvi Contents Chapter 13: Graphics and Audio 361 Linux and Graphics 361 X Windows 362 Open Graphics Library 364 OpenGL Utilities Toolkit 365 Simple Directmedia Layer 365 Writing OpenGL Applications 365 Downloading and Installing 366 Programming Environment 367 Using the GLUT Library 368 Writing SDL Applications 382 Downloading and Installing 382 Programming Environment 383 Using the SDL Library 383 Summary 394 Chapter 14: LAMP 395 What Is LAMP? 395 Apache 396 MySQL 396 PHP 397 The Rebel Platform 397 Evaluating the LAMP Platform 397 Apache 399 Virtual Hosting 400 Installation and Configuration of PHP 5 401 Apache Basic Authentication 402 Apache and SSL 402 Integrating SSL with HTTP Authentication 403 MySQL 404 Installing MySQL 404 Configuring and Starting the Database 404 Changing the Default Password 405 The MySQL Client Interface 405 Relational Databases 405 SQL 406 The Relational Model 409 PHP 411 The PHP Language 411 Error Handling 420 Error-Handling Exceptions 421 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xvi xvii Contents Optimization Techniques 422 Installing Additional PHP Software 427 Logging 427 Parameter Handling 428 Session Handling 429 Unit Testing 430 Databases and PHP 432 PHP Frameworks 432 The DVD Library 433 Version 1: The Developer’s Nightmare 433 Version 2: Basic Application with DB-Specific Data Layer 434 Version 3: Rewriting the Data Layer,Adding Logging and Exceptions 437 Version 4: Applying a Templating Framework 441 Summary 442 Index 443 GNU 47 Acknowledgments ix Introduction xix Chapter 1: Working with Linux 1 A Brief History of Linux 2 The GNU Project 2 The Linux Kernel 3 Linux Distributions 4 Free Software vs. Open Source 4 Beginning Development 5 Choosing a Linux Distribution 6 Installing a Linux Distribution 8 Linux Community 15 Linux User Groups 15 Mailing lists 16 IRC 16 Private Communities 16 Key Differences 16 Linux Is Modular 17 Linux Is Portable 17 Linux Is Generic 17 Summary 18 Chapter 2: Toolchains 19 The Linux Development Process 19 Working with Sources 20 Configuring to the Local Environment 21 Building the Sources 22 Components of the GNU Toolchain 23 The GNU Compiler Collection 23 The GNU binutils 34 GNU Make 39 The GNU Debugger 40 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xi xii Contents The Linux Kernel and the GNU Toolchain 44 Inline Assembly 44 Attribute Tags 45 Custom Linker Scripts 45 Cross-Compilation 46 Building the GNU Toolchain 47 Summary 48 Chapter 3: Portability 49 The Need for Portability 50 The Portability of Linux 51 Layers of Abstraction 51 Linux Distributions 52 Building Packages 57 Portable Source Code 70 Internationalization 81 Hardware Portability 88 64-Bit Cleanliness 89 Endian Neutrality 89 Summary 92 Chapter 4: Software Configuration Management 93 The Need for SCM 94 Centralized vs. Decentralized Development 95 Centralized Tools 95 The Concurrent Version System 96 Subversion 104 Decentralized tools 108 Bazaar-NG 109 Linux kernel SCM (git) 112 Integrated SCM Tools 115 Eclipse 115 Summary 117 Chapter 5: Network Programming 119 Linux Socket Programming 119 Sockets 120 Network Addresses 122 Using Connection-Oriented Sockets 123 Using Connectionless Sockets 130 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xii xiii Contents Moving Data 133 Datagrams vs. Streams 133 Marking Message Boundaries 137 Using Network Programming Libraries 140 The libCurl Library 140 Using the libCurl Library 141 Summary 147 Chapter 6: Databases 149 Persistent Data Storage 149 Using a Standard File 150 Using a Database 150 The Berkeley DB Package 152 Downloading and Installing 153 Building Programs 154 Basic Data Handling 154 The PostgreSQL Database Server 165 Downloading and Installing 165 Building Programs 167 Creating an Application Database 167 Connecting to the Server 169 Executing SQL Commands 173 Using Parameters 181 Summary 184 Chapter 7: Kernel Development 185 Starting Out 185 Kernel Concepts 199 A Word of Warning 200 The Task Abstraction 200 Virtual Memory 205 Don’t Panic! 208 Kernel Hacking 208 Loadable Modules 209 Kernel Development Process 211 Git: the “Stupid Content Tracker” 212 The Linux Kernel Mailing List 213 The “mm” Development Tree 215 The Stable Kernel Team 215 LWN: Linux Weekly News 216 Summary 216 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiii xiv Contents Chapter 8: Kernel Interfaces 217 What Is an Interface? 217 Undefined Interfaces 218 External Kernel Interfaces 219 System Calls 219 The Device File Abstraction 224 Kernel Events 238 Ignoring Kernel Protections 239 Internal Kernel Interfaces 243 The Kernel API 243 The kernel ABI 244 Summary 245 Chapter 9: Linux Kernel Modules 247 How Modules Work 247 Extending the Kernel Namespace 250 No Guaranteed Module Compatibility 251 Finding Good Documentation 251 Linux Kernel Man Pages 251 Writing Linux Kernel Modules 252 Before You Begin 253 Essential Module Requirements 253 Logging 256 Exported Symbols 257 Allocating Memory 259 Locking considerations 267 Deferring work 275 Further Reading 283 Distributing Linux Kernel Modules 284 Going Upstream 284 Shipping Sources 284 Shipping Prebuilt Modules 284 Summary 285 Chapter 10: Debugging 287 Debugging Overview 287 A Word about Memory Management 288 Essential Debugging Tools 289 The GNU Debugger 289 Valgrind 298 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值