linux常用头文件详解(转)
(2012-03-26 15:13:19) 标签: 杂谈 | 分类: unix/linux环境高级编程 |
首先说明几点:
1 Linux内核所在目录为/usr/src/kernels/...
2 Linux头文件所在目录为/usr/include/...
3 找不见头文件可以用find命令查找 find / -name *.h
linux常用头文件如下:
POSIX标准定义的头文件
<dirent.h>
<fcntl.h>
<fnmatch.h>
<glob.h>
<grp.h>
<netdb.h>
<pwd.h>
<regex.h>
<tar.h>
<termios.h>
<unistd.h>
<utime.h>
<wordexp.h>
-------------------------
<arpa/inet.h>
<net/if.h>
<netinet/in.h>
<netinet/tcp.h>
-------------------------
<sys/mman.h>
<sys/select.h>
<sys/socket.h>
<sys/stat.h>
<sys/times.h>
<sys/types.h>
<sys/un.h>
<sys/utsname.h>
<sys/wait.h>
------------------------------
POSIX定义的XSI扩展头文件
<cpio.h>
<dlfcn.h>
<fmtmsg.h>
<ftw.h>
<iconv.h>
<langinfo.h>
<libgen.h>
<monetary.h>
<ndbm.h>
<nl_types.h>
<poll.h>
<search.h>
<strings.h>
<syslog.h>
<ucontext.h>
<ulimit.h>
<utmpx.h>
-----------------------------
<sys/ipc.h>
<sys/msg.h>
<sys/resource.h>资源操作
<sys/sem.h>
<sys/shm.h>
<sys/statvfs.h>
<sys/time.h>
<sys/timeb.h>
<sys/uio.h>
------------------------------
POSIX定义的可选头文件
<aio.h>
<mqueue.h>
<pthread.h>
<sched.h>
<semaphore.h>
<spawn.h>
<stropts.h>
<trace.h>
3、 C/C++头文件一览
C
#i nclude <assert.h> //设定插入点
#i nclude <ctype.h> //字符处理
#i nclude <errno.h> //定义错误码
#i nclude <float.h> //浮点数处理
#i nclude <iso646.h>
#i nclude <limits.h> //定义各种数据类型最值的常量
#i nclude <locale.h> //定义本地化C函数
#i nclude <math.h> //定义数学函数
#i nclude <setjmp.h>
#i nclude <signal.h>
#i nclude <stdarg.h>
#i nclude <stddef.h>
#i nclude <stdio.h> //定义输入/输出函数
#i nclude <stdlib.h> //定义杂项函数及内存分配函数如malloc、free、system、atoi、atol、rand、exit等
#i nclude <string.h> //字符串处理,strlen(),strcat(),strcpy(),strcmp()等等
#i nclude <time.h> //定义关于时间的函数
#i nclude <wchar.h> //宽字符处理及输入/输出
#i nclude <wctype.h> //宽字符分类
传统C++
#i nclude <fstream.h> //改用<fstream>
#i nclude <iomanip.h> //改用<iomainip>
#i nclude <iostream.h> //改用<iostream>
#i nclude <strstrea.h> //该类不再支持,改用<sstream>中的stringstream
————————————————————————————————
标准C++
#i nclude <algorithm> //STL 通用算法
#i nclude <bitset> //STL 位集容器
#i nclude <cctype>
#i nclude <cerrno> //定义错误码
#i nclude <cfloat> //浮点数处理
#i nclude <ciso646>
#i nclude <climits> //定义各种数据类型最值的常量
#i nclude <clocale> //定义本地化函数
#i nclude <cmath> //定义数学函数
#i nclude <complex> //复数类
#i nclude <csignal>
#i nclude <csetjmp>
#i nclude <cstdarg>
#i nclude <cstddef>
#i nclude <cstdio> //定义输入/输出函数
#i nclude <cstdlib> //定义杂项函数及内存分配函数
#i nclude <cstring> //字符串处理
#i nclude <ctime> //定义关于时间的函数
#i nclude <cwchar> //宽字符处理及输入/输出
#i nclude <cwctype> //宽字符分类
#i nclude <deque> //STL 双端队列容器
#i nclude <exception> //异常处理类
#i nclude <fstream> //文件输入/输出
#i nclude <al> //STL 定义运算函数(代替运算符)
#i nclude <limits> //定义各种数据类型最值常量
#i nclude <list> //STL 线性列表容器
#i nclude <locale>
#i nclude <map> //STL 映射容器
#i nclude <memory>
#i nclude <new>
#i nclude <numeric>
#i nclude <iomanip> //参数化输入/输出
#i nclude <ios> //基本输入/输出支持
#i nclude <iosfwd> //输入/输出系统使用的前置声明
#i nclude <iostream> //数据流输入/输出
#i nclude <istream> //基本输入流
#i nclude <iterator>
#i nclude <ostream> //基本输出流
#i nclude <queue> //STL 队列容器
#i nclude <set> //STL 集合容器
#i nclude <sstream> //基于字符串的流
#i nclude <stack> //STL 堆栈容器
#i nclude <stdexcept> //标准异常类
#i nclude <streambuf> //底层输入/输出支持
#i nclude <string> //字符串类
#i nclude <typeinfo>
#i nclude <utility> //STL 通用模板类
#i nclude <valarray>
#i nclude <vector> //STL 动态数组容器
————————————————————————————————
C99增加的部分
#i nclude <complex.h> //复数处理
#i nclude <fenv.h> //浮点环境
#i nclude <inttypes.h> //整数格式转换
#i nclude <stdbool.h> //布尔环境
#i nclude <stdint.h> //整型环境
#i nclude <tgmath.h> //通用类型数学宏
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/wubin1124/archive/2009/12/09/4971359.aspx
***********************************************************************************************************************************
程序在使用一个函数之前,应该首先声明该函数。为了便于使用,通常的做法是把同一类函数或数据结构以及常数的声明放在一个头文件(header file)中。头文件中也可以包括任何相关的类型定义和宏(macros)。在程序源代码文件中则使用预处理指令“#include”来引用相关的头文件。
程序中如下形式的一条控制行语句将会使得该行被文件filename的内容替换掉:
# include
当然,文件名filename中不能包含 > 和换行字符以及 "、'、\、或 /* 字符。编译系统会在定义的一系列地方搜索这个文件。类似地,下面形式的控制行会让编译器首先在源程序所在目录中搜索filename文件:
# include "filename"
如果没有找到,编译器再执行同上面一样的搜索过程。在这种形式中,文件名filename中不能包含换行字符和 "、'、\、或 /* 字符,但允许使用 > 字符。
在一般应用程序源代码中,头文件与开发环境中的库文件有着不可分割的紧密联系,库中的每个函数都需要在头文件中加以声明。应用程序开发环境中的头文件(通常放置在系统/usr/include/目录中)可以看作是其所提供函数库(例如libc.a)中函数的一个组成部分,是库函数的使用说明或接口声明。在编译器把源代码程序转换成目标模块后,链接程序(linker)会把程序所有的目标模块组合在一起,包括用到的任何库文件中的模块。从而构成一个可执行的程序。
对于标准C函数库来讲,其最基本的头文件有15个。每个头文件都表示出一类特定函数的功能说明或结构定义,例如I/O操作函数、字符处理函数等。有关标准函数库的详细说明及其实现可参照Plauger编著的《The Standard C Library》一书。
而对于本书所描述的内核源代码,其中涉及的头文件则可以看作是对内核及其函数库所提供服务的一个概要说明,是内核及其相关程序专用的头文件。在这些头文件中主要描述了内核所用到的所有数据结构、初始化数据、常数和宏定义,也包括少量的程序代码。除了几个专用的头文件以外(例如块设备头文件blk.h),Linux 0.12内核中所用到的头文件都放在内核代码树的include/目录中。因此编译Linux 0.12内核无需使用开发环境提供的位于/usr/include/目录下的任何头文件。当然,tools/build.c程序除外。因为这个程序虽然被包含在内核源代码树中,但它只是一个用于组合创建内核映像文件的工具程序或应用程序,不会被链接到内核代码中。
从0.95版开始,内核代码树中的头文件需要复制到/usr/include/linux目录下才能顺利地编译内核。即从该版内核开始头文件已经与开发环境使用的头文件合二为一。