https://blog.csdn.net/BjarneCpp/article/details/76135980

起因

我拿到了一套Linux下的C++代码,代码中有这个头文件#include <unistd.h>,在Windows上查看缺少这个头文件,而这个头文件就是Linux中的系统文件。

困惑

因此我想在Linux下去查找这个文件。通过Linux指令:

locate unistd.h

查找结果下图所示: 

查找出来这么多路径下的同名文件,不知道要用哪一个unistd.h。因此必须要找g++或者gcc头文件搜索路径。

方法

我在这里 C/C++ search path(头文件搜索路径) - MJN - CSDN博客 找到了办法。

这里 GCC The C Preprocessor: Search Path 讲述了如何去查看GCC的搜索路径。我把内容粘贴到这里:

Search Path

By default, the preprocessor looks for header files included by the quote form of the directive #include “file” first relative to the directory of the current file, and then in a preconfigured list of standard system directories. For example, if /usr/include/sys/stat.h contains #include “types.h”, GCC looks for types.h first in /usr/include/sys, then in its usual search path.

For the angle-bracket form #include , the preprocessor’s default behavior is to look only in the standard system directories. The exact search directory list depends on the target system, how GCC is configured, and where it is installed. You can find the default search directory list for your version of CPP by invoking it with the -v option. For example,

cpp -v /dev/null -o /dev/null

There are a number of command-line options you can use to add additional directories to the search path. The most commonly-used option is -Idir, which causes dir to be searched after the current directory (for the quote form of the directive) and ahead of the standard system directories. You can specify multiple -I options on the command line, in which case the directories are searched in left-to-right order.

If you need separate control over the search paths for the quote and angle-bracket forms of the ‘#include’ directive, you can use the -iquote and/or -isystem options instead of -I. See Invocation, for a detailed description of these options, as well as others that are less generally useful.

If you specify other options on the command line, such as -I, that affect where the preprocessor searches for header files, the directory list printed by the -v option reflects the actual search path used by the preprocessor.

Note that you can also prevent the preprocessor from searching any of the default system header directories with the -nostdinc option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself.

解决

我在Linux终端执行了这条指令:

cpp -v /dev/null -o /dev/null

显示效果如图所示: 

最后我根据之前locate unistd.h查找到的路径(看图一),比对图二中的路径,确定就能在/usr/include路径下,找到我想要的unistd.h文件。

Linux 中C/C++ search path(头文件搜索路径)的更多相关文章

  1. Linux下的头文件搜索路径

         对于以压缩包发布的软件,在它的目录下通常都有一个配置脚本configure,它的作用确定编译参数(比如头文件位置.连接库位置等),然后生成Makefile以编译程序.可以进入该软件的目录,执 ...

  2. Xcode增加头文件搜索路径的方法

    Xcode增加头文件搜索路径的方法 以C++工程为例: 在Build Settings 页面中的Search Paths一节就是用来设置头文件路径. 相关的配置项用红框框起来了,共有三个配置项: He ...

  3. Linux C语言头文件搜索路径

    本文介绍在linux中头文件的搜索路径,也就是说你通过include指定的头文件,linux下的gcc编译器它是怎么找到它的呢.在此之前,先了解一个基本概念. 头文件是一种文本文件,使用文本编辑器将代 ...

  4. linux下编译时的默认库和头文件搜索路径

    链接库路径 默认的链接库路径,定义在搜索/etc/ld.so.conf下的一些路径,其包含了一些重要的系统位置:LIBRARY_PATH, 但如果定义了LD_LIBRARY_PATH, 动态库的搜索路 ...

  5. eclipse C开发添加自己的头文件搜索路径

    eclipse编译C程序时提示: ..\src\main.c:8:21: fatal error: my_type.h: No such file or directory 如图: 需要添加自己的头文 ...

  6. [转]Linux学习笔记——例说makefile 头文件查找路径

    0.前言     从学习C语言开始就慢慢开始接触makefile,查阅了很多的makefile的资料但总感觉没有真正掌握makefile,如果自己动手写一个makefile总觉得非常吃力.所以特意借助 ...

  7. linux gcc头文件搜索路径

    #include <>: 直接到系统指定的某些目录中去找某些头文件.#include "": 先到源文件所在文件夹去找,然后再到系统指定的某些目录中去找某些头文件 1. ...

  8. Linux学习笔记——例说makefile 头文件查找路径

    0.前言     从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...

  9. GCC编译默认的头文件搜索路径

    对于c语言来说: gcc -xc -E -v - 截图: 对于c++来说: gcc -xc++ -E -v - 截图: gcc的arg和opt解释: 后面一干啥作用暂时不知道

随机推荐

  1. Spark的HA部署

    一.安装JDK.Scala 二.安装zookeeper 三.安装Hadoop 四.安装Spark 1.修改spark/conf/spark-env.sh export JAVA_HOME=/usr/j ...

  2. Deep Learning系统实训之二:梯度下降原理

    基本概念理解: 一个epoch:当前所有数据都跑(迭代)了一遍: 那么两个epoch,就是把所有数据跑了两遍,三个epoch就是把所有数据跑了三遍,以此类推. batch_size:每次迭代多少个数据 ...

  3. LeetCode(5):最长回文子串

    Medium! 题目描述: 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 长度最长为1000. 示例: 输入: "babad" 输出: "bab&quo ...

  4. wpf 来回拉动滚动条抛异常

    其中的控件,来回快速的来动滚动条,抛如下异常,但是完全代码捕捉不到. 这个树用到了VirtualizingStackPanel.IsVirtualizing="True".去掉该句 ...

  5. ubuntu 查看进程信息

    查看进程信息 ps ps -aux 查看所有进程,每行一个程序 top 显示当前运行程序 kill 98 (98为PID号,) kill -9 98 (强制杀死98) ps -e Linux如何查看端 ...

  6. 将eclipse的maven项目导入到intellij idea中

    最近项目中需要用到idea,需要将原来的eclipse项目进行转移.捣鼓了半天终于成功了,在这里和大家分享下,希望对大家有所帮助,如有错误,欢迎指正. idea的确是一款很智能的开发工具,真的是爱不释 ...

  7. 全局JavaScript对象

  8. bzoj3687

    3687: 简单题 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 700  Solved: 319[Submit][Status][Discuss] ...

  9. 【Java】 剑指offer(53-1) 数字在排序数组中出现的次数

    正文 本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 统计一个数字在排序数组中出现的次数.例如输入排序数组{1, ...

  10. 附002.Docker常见命令

    # docker --help Usage: docker [OPTIONS] COMMAND [arg...] docker daemon [ --help | ... ] docker [ -h ...