Linux下GCC编程四个过程(1)
在Linux下进行C语言
编程,必然要采用GNU GCC来编译C源代码生成可执行程序。
一、GCC快速
入门
Gcc指令的一般格式为:Gcc [选项] 要编译的文件 [选项] [目标文件]
其中,目标文件可缺省,Gcc默认生成可执行的文件名为:编译文件.out
我们来看一下经典
入门程序"Hello World!"
# vi hello.c
#include <stdlib.h>
#include <stdio.h>
void main(void)
{
printf("hello world!\r\n");
}
用gcc编译成执行程序。
#gcc hello.c
该命令将hello.c直接生成最终二进制可执行程序a.out
这条命令隐含执行了(1)预处理、(2)汇编、(3)编译并(4)链接形成最终的二进制可执行程序。这里未指定输出文件,默认输出为a.out。
如何要指定最终二进制可执行程序名,那么用-o选项来指定名称。比如需要生成执行程序hello.exe
那么
#gcc hello.c -o hello.exe
二、GCC的命令剖析--四步走
从上面我们知道GCC编译源代码生成最终可执行的二进制程序,GCC后台隐含执行了四个阶段步骤。
GCC编译C源码有四个步骤:
预处理-----> 编译 ----> 汇编 ----> 链接
现在我们就用GCC的命令选项来逐个剖析GCC过程。
1)预处理(Pre-processing)
在该阶段,编译器将C源代码中的包含的头文件如stdio.h编译进来,用户可以使用gcc的选项”-E”进行查看。
用法:#gcc -E hello.c -o hello.i
作用:将hello.c预处理输出hello.i文件。
[root]# gcc -E hello.c -o hello.i
[root]# ls
hello.c hello.i
[root]# vi hello.i
# 1 "hello.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "hello.c"
# 1 "/usr/include/stdlib.h" 1 3
# 25 "/usr/include/stdlib.h" 3
# 1 "/usr/include/features.h" 1 3
# 291 "/usr/include/features.h" 3
# 1 "/usr/include/sys/cdefs.h" 1 3
# 292 "/usr/include/features.h" 2 3
# 314 "/usr/include/features.h" 3
# 1 "/usr/include/gnu/stubs.h" 1 3
# 315 "/usr/include/features.h" 2 3
# 26 "/usr/include/stdlib.h" 2 3
# 3 "hello.c" 2
void main(void)
{
printf("hello world!\r\n");
}
相关文档:
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.
~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时, ......
参见:http://isis.poly.edu/kulesh/stuff/src/klist/
Introduction:
Linux kernel is mostly written in the C language. Unlike many other languages C does not have
a good collection of data structures built into it or supported by a collection of standard libraries.
Therefore, you're probably excited ......
二、安装Mysql
1、下载MySQL的安装文件
安装MySQL需要下面两个文件:
MySQL-server-4.0.16-0.i386.rpm
MySQL-client-4.0.16-0.i386.rpm
下载地址为:http://www.mysql.com/downloads/mysql-4.0.html, 打开此网页
,
下拉网页找到“Linux x86 RPM downloads”项,找到&ldq ......
Linux内核中的双循环链表
2006-11-27 19:14
双循环链表传统实现
在传统的双循环链表实现中,如果创建某种数据结构的双循环链表,通常采用的办法是在这个数据结构的类型定义中加入两个(指向该类型对象的)指针next和prev。例如:
typedef struct foo {
…
struct foo *p ......