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. PHP 获取时间

    1.获取系统当前时间 echo "date('Y-m-d',time())"; 2.获取系统前一天时间 echo "date("Y-m-d",strt ...

  2. [转]notepad++ java编码,输出中文字符时,编译出错

    呆在公司中,最近受开发手机app的几个同事影响,想学android的开发,心血来潮,挡也挡不住,说干就干,直接看教程,发现有很多关于java的语法知识不懂,于是又来学java,学习的过程中难免出现问题 ...

  3. Codeforces 514E Darth Vader and Tree 矩阵快速幂

    Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...

  4. Python 时间获取

    摘自:http://www.jb51.net/article/91365.htm 摘自:https://www.cnblogs.com/liuq/p/6211005.html 一.在python中,除 ...

  5. Scala入门教程---《chang哥教你一天搞定Scala》

    <chang哥教你一天搞定Scala> /** * <chang哥教你一天搞定Scala> * scala是一门多范式编程语言,集成了面向对象编程和函数式编程等多种特性. * ...

  6. 【Java】 剑指offer(20) 表示数值的字符串

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如, ...

  7. 004 Spark中的local模式的配置以及测试

    一:介绍 1.Spark的模式 Local:本地运行模式,主要用于开发.测试 Standalone:使用Spark自带的资源管理框架运行Spark程序,30%左右 Yarn: 将spark应用程序运行 ...

  8. 洛谷 p1044 栈 【Catalan(卡特兰数)】【经典题】

    题目链接:https://www.luogu.org/problemnew/show/P1044 转载于:https://www.luogu.org/blog/QiXingZhi/solution-p ...

  9. 微信小程序:一起玩连线,一个算法来搞定

    微信小程序:一起玩连线 游戏玩法 将相同颜色的结点连接在一起,连线之间不能交叉. 算法思想 转换为多个源点到达对应终点的路径问题,且路径之间不相交.按照dfs方式寻找两个结点路径,一条路径探索完之后, ...

  10. 虚拟机克隆后导致两台机器的IP都不显示的解决方法

    centos7中输入ifconfig出现ens33,没有eth0,也没有ip,不能上网,输入ifconfig后如下图 之前在网上也找了很多的方法,比如删除文件70-persistent-ipoib.r ...