Linux 中C/C++ search path(头文件搜索路径)
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(头文件搜索路径)的更多相关文章
- Linux下的头文件搜索路径
对于以压缩包发布的软件,在它的目录下通常都有一个配置脚本configure,它的作用确定编译参数(比如头文件位置.连接库位置等),然后生成Makefile以编译程序.可以进入该软件的目录,执 ...
- Xcode增加头文件搜索路径的方法
Xcode增加头文件搜索路径的方法 以C++工程为例: 在Build Settings 页面中的Search Paths一节就是用来设置头文件路径. 相关的配置项用红框框起来了,共有三个配置项: He ...
- Linux C语言头文件搜索路径
本文介绍在linux中头文件的搜索路径,也就是说你通过include指定的头文件,linux下的gcc编译器它是怎么找到它的呢.在此之前,先了解一个基本概念. 头文件是一种文本文件,使用文本编辑器将代 ...
- linux下编译时的默认库和头文件搜索路径
链接库路径 默认的链接库路径,定义在搜索/etc/ld.so.conf下的一些路径,其包含了一些重要的系统位置:LIBRARY_PATH, 但如果定义了LD_LIBRARY_PATH, 动态库的搜索路 ...
- eclipse C开发添加自己的头文件搜索路径
eclipse编译C程序时提示: ..\src\main.c:8:21: fatal error: my_type.h: No such file or directory 如图: 需要添加自己的头文 ...
- [转]Linux学习笔记——例说makefile 头文件查找路径
0.前言 从学习C语言开始就慢慢开始接触makefile,查阅了很多的makefile的资料但总感觉没有真正掌握makefile,如果自己动手写一个makefile总觉得非常吃力.所以特意借助 ...
- linux gcc头文件搜索路径
#include <>: 直接到系统指定的某些目录中去找某些头文件.#include "": 先到源文件所在文件夹去找,然后再到系统指定的某些目录中去找某些头文件 1. ...
- Linux学习笔记——例说makefile 头文件查找路径
0.前言 从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...
- GCC编译默认的头文件搜索路径
对于c语言来说: gcc -xc -E -v - 截图: 对于c++来说: gcc -xc++ -E -v - 截图: gcc的arg和opt解释: 后面一干啥作用暂时不知道
随机推荐
- hdu4638 莫队算法
莫队算法基础题,题目看懂就能做出来 #include<iostream> #include<cstring> #include<cstdio> #include&l ...
- poj1511,线段树扫描线面积
经典题,线段树扫描线其实类似区间更新,一般的做法是想象一根扫描线从上扫到下或者从左扫到右,本题的做法是从上扫到下 只要扫到了一根水平线,就将其更新到线段树对应区间中,区间和它的子区间是独立更新的 #i ...
- python接口自动化测试二十二:文件下载
文件下载类型: Content-Type: octets/stream 一般为文件类型:
- 集合Arraylist的方法的使用和打印
package chapter090; import java.util.ArrayList;import java.util.List; public class TestList01 { publ ...
- Masm615+notepad++6.8.8搭建汇编开发环境
前言:很早以前搭过,做了笔记的.现在重新玩汇编,按照笔记撘环境,谁知道坑了自己两个小时,气的我现在打字手都在抖 准备工作: 1.Masm615汇编环境,下载地址:https://pan.baidu.c ...
- BZOJ1195 [HNOI2006]最短母串 AC自动机 bfs
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 传送门 - BZOJ1195 题意概括 给出一堆串,然后求一个包含这些串的所有串的最短的中的字典序最小的. 题解 先造一个AC ...
- ajax请求正常,返回json格式,后台没问题,浏览器500
1.使用的是springmvc中的 @ResponseBody 注解 ,后台不报错,.正常走完:以为使用这个注解就可以正常返回json格式的数据:所以一直没有怀疑是注解的问题: 以为是ajax本身 ...
- 全排列问题(递归&非递归&STL函数)
问题描述: 打印输出1-9的所有全排序列,或者打印输出a-d的全排列. 思路分析: 将每个元素放到余下n-1个元素组成的队列最前方,然后对剩余元素进行全排列,依次递归下去. 比如:1 2 3 为例首先 ...
- Linux —— 文件处理指令
- centos关机、重启、图形界面与命令行界面切换命令
1.关机: init0; poweroff; halt; shutdown 2.重启: init1; reboot; 3.图形界面切换到命令行界面: init3; 或者,修改配置文件: #vi ...