以#include <sys/stat.h>为例,分析Linux系统下编译所需要头文件

eg:

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <linux/msm_ion.h>
#include <utils/Log.h>
#include "QSEEComAPI.h"
#include "common_log.h"
#include <sys/mman.h>
#include <semaphore.h>

注意:在linux中,大部分的头文件都在/usr/include目录下, 如果头文件前再有目录,比如sys/stat.h, 则在/usr/include下会有相应sys目录,然后cd进去,再查看头文件即可.

         还可以通过find /usr/include -name stat.h  或try "/usr/include/sys/sat.h"去搜索。

        如果不知道该函数的用法,可以通过man函数,man 2 stat去试一下(其中2代表man手册的第二节),该函数的用法和所需要的头文件;

示例:

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

int main() {
    struct stat buf;
    stat("/etc/hosts", &buf);
    printf("/etc/hosts file size = %d\n", buf.st_size);

posted on 2016-02-23 10:09  happy刘艺  阅读(4626)  评论(0编辑  收藏  举报

导航