转载------ #include sys/xxx.h 头文件

本文详细介绍了Linux系统中的系统头文件结构,包括POSIX标准定义的头文件及其作用,以及如何在不同环境下正确使用应用程序头文件。重点讨论了头文件在不同系统间的兼容性和迁移问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




#include sys/xxx.h是Linux系统中的系统头文件

 
应用程序的头文件在/usr/include下(比如fedora9下),因为应用程序是在fedora9下编译的,所以应用程序的头文件一定要来自fedora9下,而把编译的可行性文件如test,通过nfs挂载到开发板上运行的时候,内核中的头文件都是在如linux2.6.24,它里面的都是内核用的头文件。
 
位于linux系统下/usr/include/sys/文件下面
POSIX标准定义的头文件
<dirent.h>          目录项
<fcntl.h>           文件控制
<fnmatch.h>         文件名匹配类型
<glob.h>            路径名模式匹配类型
<grp.h>             组文件
<netdb.h>           网络数据库操作
<pwd.h>             口令文件
<regex.h>           正则表达式
<tar.h>             TAR归档值
<termios.h>         终端I/O
<unistd.h>          符号常量
<utime.h>           文件时间
<wordexp.h>         字符扩展类型

<arpa/inet.h>       INTERNET定义
<net/if.h>          套接字本地接口
<netinet/in.h>      INTERNET地址族
<netinet/tcp.h>     传输控制协议定义

<sys/mman.h>        内存管理声明
<sys/select.h>      Select函数
<sys/socket.h>      套接字借口
<sys/stat.h>        文件状态
<sys/times.h>       进程时间
<sys/types.h>       基本系统数据类型
<sys/un.h>          UNIX域套接字定义
<sys/utsname.h>     系统名
<sys/wait.h>        进程控制

POSIX定义的XSI扩展头文件
<cpio.h>            cpio归档值    
<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>         IPC(命名管道)
<sys/msg.h>         消息队列
<sys/resource.h>    资源操作
<sys/sem.h>         信号量
<sys/shm.h>         共享存储
<sys/statvfs.h>     文件系统信息
<sys/time.h>        时间类型
<sys/timeb.h>       附加的日期和时间定义
<sys/uio.h>         矢量I/O操作

POSIX定义的可选头文件
<aio.h>             异步I/O
<mqueue.h>          消息队列
<pthread.h>         线程
<sched.h>           执行调度
<semaphore.h>       信号量
<spawn.h>           实时spawn接口
<stropts.h>         XSI STREAMS接口
<trace.h>           事件跟踪

#include <unistd.h>
对于内核而言,所有打开文件都由文件描述符引用。文件描述符是一个非负整数。当打开一个现存文件或创建一个新文件时,内核向进程返回一个文件描述符。当读、写一个文件时,用open或creat返回的文件描述符标识该文件,将其作为参数传送给read或write。按照惯例,UNIX   shell使文件描述符0与进程的标准输入相结合,文件描述符1与标准输出相结合,文件描述符2与标准出错输出相结合。这是UNIX   shell以及很多应用程序使用的惯例,而与内核无关。尽管如此,如果不遵照这种惯例,那么很多LINUX应用程序就不能工作。在POSIX.1应用程序中,幻数0、1、2应被代换成符号常数STDIN_FILENO、STDOUT_FILENO和STDERR_FILENO。这些常数和类型都定义在头文 <unistd.h>中。
Build started: Project: stm32h723 *** Using Compiler 'V6.22', folder: 'E:\keil 541\ARM\ARMCLANG\Bin' Build target 'stm32h723' ../Drivers/BSP/LCD/lcd.c(15): warning: In file included from... ../Drivers/BSP/LCD\lcd.h(19): error: './BSP/LCD/ltdc.h' file not found 19 | #include "./BSP/LCD/ltdc.h" | ^~~~~~~~~~~~~~~~~~ 1 error generated. compiling lcd.c... ../Drivers/BSP/KEY/key.c(15): warning: In file included from... ../Drivers/BSP/KEY\../../SYSTEM/delay/delay.h(21): error: './SYSTEM/sys/sys.h' file not found 21 | #include "./SYSTEM/sys/sys.h" | ^~~~~~~~~~~~~~~~~~~~ 1 error generated. compiling key.c... ../Drivers/BSP/NORFLASH/norflash.c(14): warning: In file included from... ../Drivers/BSP/NORFLASH\../QSPI/qspi.h(17): error: './SYSTEM/sys/sys.h' file not found 17 | #include "./SYSTEM/sys/sys.h" | ^~~~~~~~~~~~~~~~~~~~ 1 error generated. compiling norflash.c... ../Drivers/BSP/MPU/mpu.c(16): error: './SYSTEM/usart/usart.h' file not found 16 | #include "./SYSTEM/usart/usart.h" | ^~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. compiling mpu.c... ../Drivers/BSP/TOUCH/touch.c(18): error: './BSP/LCD/lcd.h' file not found 18 | #include "./BSP/LCD/lcd.h" | ^~~~~~~~~~~~~~~~~ 1 error generated. compiling touch.c... ../Drivers/BSP/TOUCH/gt9xxx.c(17): error: './BSP/LCD/lcd.h' file not found 17 | #include "./BSP/LCD/lcd.h" | ^~~~~~~~~~~~~~~~~ 1 error generated. compiling gt9xxx.c... ../Drivers/BSP/SDRAM/sdram.c(14): error: './BSP/SDRAM/sdram.h' file not found 14 | #include "./BSP/SDRAM/sdram.h" | ^~~~~~~~~~~~~~~~~~~~~ 1 error generated. compiling sdram.c... ../Drivers/BSP/TOUCH/ctiic.c(14): error: './BSP/TOUCH/ctiic.h' file not found 14 | #include "./BSP/TOUCH/ctiic.h" | ^~~~~~~~~~~~~~~~~~~~~ 1 error generated. compiling ctiic.c... ../Drivers/BSP/QSPI/qspi.c(14): error: './BSP/QSPI/qspi.h' file not found 14 | #include "./BSP/QSPI/qspi.h" | ^~~~~~~~~~~~~~~~~~~ 1 error generated. compiling qspi.c... ../Drivers/BSP/TOUCH/ft5206.c(15): error: './BSP/LCD/lcd.h' file not found 15 | #include "./BSP/LCD/lcd.h" | ^~~~~~~~~~~~~~~~~ 1 error generated. compiling ft5206.c... ../Drivers/SYSTEM/delay/delay.c(18): error: 'sys.h' file not found 18 | #include "sys.h" | ^~~~~~~ 1 error generated. compiling delay.c... compiling sys.c... ../Drivers/BSP/LCD/ltdc.c(14): warning: In file included from... ../Drivers/BSP/LCD\ltdc.h(17): error: '../sys/sys.h' file not found, did you mean 'sys/sys.h'? 17 | #include "../sys/sys.h" | ^~~~~~~~~~~~~~ | "sys/sys.h" ../Drivers/BSP/LCD\ltdc.h(47): error: unknown type name 'LTDC_HandleTypeDef'; did you mean 'I2C_HandleTypeDef'? 47 | extern LTDC_HandleTypeDef g_ltdc_handle; /* LTDC<BE><E4><B1><FA> */ | ^~~~~~~~~~~~~~~~~~ | I2C_HandleTypeDef ../Drivers/STM32H7xx_HAL_Driver/Inc\stm32h7xx_hal_i2c.h(252): note: 'I2C_HandleTypeDef' declared here 252 | } I2C_HandleTypeDef; | ^ ../Drivers/BSP/LCD/ltdc.c(14): warning: In file included from... ../Drivers/BSP/LCD\ltdc.h(48): error: unknown type name 'DMA2D_HandleTypeDef'; did you mean 'DMA_HandleTypeDef'? 48 | extern DMA2D_HandleTypeDef g_dma2d_handle; /* DMA2D<BE><E4><B1><FA> */ | ^~~~~~~~~~~~~~~~~~~ | DMA_HandleTypeDef ../Drivers/STM32H7xx_HAL_Driver/Inc\stm32h7xx_hal_dma.h(179): note: 'DMA_HandleTypeDef' declared here 179 | }DMA_HandleTypeDef; | ^ ../Drivers/BSP/LCD/ltdc.c(15): error: './BSP/LCD/lcd.h' file not found 15 | #include "./BSP/LCD/lcd.h" | ^~~~~~~~~~~~~~~~~ 4 errors generated. compiling ltdc.c... ../Drivers/SYSTEM/usart/usart.c(16): warning: In file included from... ../Drivers/SYSTEM/usart\usart.h(44): error: unknown type name 'UART_HandleTypeDef' 44 | extern UART_HandleTypeDef g_uart1_handle; /* UART<BE><E4><B1><FA> */ | ^ ../Drivers/SYSTEM/usart/usart.c(95): error: unknown type name 'UART_HandleTypeDef' 95 | UART_HandleTypeDef g_uart1_handle; /* UART<BE><E4><B1><FA> */ | ^ ../Drivers/SYSTEM/usart/usart.c(109): error: use of undeclared identifier 'UART_WORDLENGTH_8B' 109 | g_uart1_handle.Init.WordLength = UART_WORDLENGTH_8B; /* <D7>殖<A4>为8位<CA><FD><BE>莞<F1>式 */ | ^ ../Drivers/SYSTEM/usart/usart.c(110): error: use of undeclared identifier 'UART_STOPBITS_1' 110 | g_uart1_handle.Init.StopBits = UART_STOPBITS_1; /* 一<B8><F6>停止位 */ | ^ ../Drivers/SYSTEM/usart/usart.c(111): error: use of undeclared identifier 'UART_PARITY_NONE' 111 | g_uart1_handle.Init.Parity = UART_PARITY_NONE; /* <CE><DE><C6><E6>偶校<D1><E9>位 */ | ^ ../Drivers/SYSTEM/usart/usart.c(112): error: use of undeclared identifier 'UART_HWCONTROL_NONE' 112 | g_uart1_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; /* <CE><DE>硬<BC><FE><C1><F7><BF><D8> */ | ^ ../Drivers/SYSTEM/usart/usart.c(113): error: use of undeclared identifier 'UART_MODE_TX_RX' 113 | g_uart1_handle.Init.Mode = UART_MODE_TX_RX; /* <CA>辗<A2>模式 */ | ^ ../Drivers/SYSTEM/usart/usart.c(114): error: call to undeclared function 'HAL_UART_Init'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 114 | HAL_UART_Init(&g_uart1_handle); /* HAL_UART_Init()<BB><E1>使<C4><DC>USART */ | ^ ../Drivers/SYSTEM/usart/usart.c(117): error: call to undeclared function 'HAL_UART_Receive_IT'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 117 | HAL_UART_Receive_IT(&g_uart1_handle, (uint8_t *)g_rx_buffer, RXBUFFERSIZE); | ^ ../Drivers/SYSTEM/usart/usart.c(127): error: unknown type name 'UART_HandleTypeDef' 127 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) | ^ ../Drivers/SYSTEM/usart/usart.c(162): error: unknown type name 'UART_HandleTypeDef' 162 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) | ^ ../Drivers/SYSTEM/usart/usart.c(198): error: call to undeclared function 'HAL_UART_Receive_IT'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 198 | HAL_UART_Receive_IT(&g_uart1_handle, (uint8_t *)g_rx_buffer, RXBUFFERSIZE); | ^ ../Drivers/SYSTEM/usart/usart.c(213): error: call to undeclared function 'HAL_UART_IRQHandler'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 213 | HAL_UART_IRQHandler(&g_uart1_handle); /* <B5><F7><D3><C3>HAL<BF><E2><D6>卸洗<A6><C0><ED><B9><AB><D3>煤<AF><CA><FD> */ | ^ 13 errors generated. compiling usart.c... "stm32h723\stm32h723.axf" - 28 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:01
06-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值