如何确定“#include< .....>”的目录。获取头文件? [英] How to determine the directories from where "#include <.....>" gets the header files?

查看:70
本文介绍了如何确定“#include< .....>”的目录。获取头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编码


#include" myheader.h"

时,会在当前目录中搜索此头文件。


但是当编写时编译器在哪里搜索头文件


#include< myheader.h>

而不是?


Pablo

When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo

推荐答案

Pablo Suarez写道:
Pablo Suarez writes:

当我编码


#include" myheader.h"


然后在当前目录中搜索这个头文件。


但是当编写时编译器在哪里搜索头文件


#include< ; myheader.h>


代替?
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?



每个编译器都有预先配置的目录列表,它会搜索头文件的
。这是特定于编译器的设置。如果你需要知道它们是什么,请查看编译器的

文档。


大多数编译器都认识到-I选项将目录添加到列表中

目录搜索头文件。顺便说一下,如果编译器确实没有找到filename.h,那么在当前目录中(实际上,不是当前的

目录,而是引用此

头文件的源文件所在的目录),它继续搜索对于filename.h,在同一个目录列表中。 filename.h与filename.h之间唯一的实际区别。并且

< filename.his在源目录中搜索前一个



----- BEGIN PGP签名-----

版本:GnuPG v1.4.7(GNU / Linux)

iD8DBQBIL5AUx9p3GYHlUOIRAm8oAJ0R1AmBVivAlOTO1pHWIp 77jKgmIgCeO2H0

eugRkuTsFq3oKysXEgfosi4 = < br $>
= gKNy

-----结束PGP签名-----

Each compiler has its on preconfigured list of directories which it searches
for the header files. This is a compiler-specific setting. Check the
documentation for your compiler if you need to know what they are.

Most compilers recognize the -I option that adds a directory to the list of
directories it searches for header files. Incidentally, if the compiler does
not find "filename.h" in the current directory (actually, not the current
directory, but the directory where the source file, that referenced this
header file, is located), it continues to search for filename.h in the same
list of directories. The only actual difference between "filename.h" and
<filename.his that the former one is searched for in the source directory
first.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBIL5AUx9p3GYHlUOIRAm8oAJ0R1AmBVivAlOTO1pHWIp 77jKgmIgCeO2H0
eugRkuTsFq3oKysXEgfosi4=
=gKNy
-----END PGP SIGNATURE-----


Pablo Suarez写道:
Pablo Suarez wrote:

当我编码


#include" myheader.h"


然后在当前目录中搜索此头文件。


但是当我写的时,编译器在哪里搜索头文件


#include< myheader.h>


代替?
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?



取决于编译器。但是编译器设置为搜索它们。

标准库头文件目录等...


你问的标准是什么,如何确定你的特定编译器或其他什么?


-

Jim Langston
ta ******* @ rocketmail.com


Pablo Suarez写道:
Pablo Suarez wrote:

当我编码


#include" myheader.h"


然后在当前目录中搜索此头文件。


但是当我写的时,编译器在哪里搜索头文件


#include< myheader.h>


代替?
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?



这有两个答案,一个用C和C ++语言给出

标准,一个适用于现实。


1.该语言定义了几个所谓的标题,如< stdio.h(C)或

< iostream(C ++)。这些根本不需要是文件,只有包含它们才需要具有特定效果的
。实际上,大多数

编译器都会在编译器安装过程中安装这些头文件。


2.实际上,你会发现它与其他编译器在同一个目录中-supplied

标题也安装在一些与系统相关的文件中。

此外,通常库会在其目录中安装头文件或添加一个

目录及其头部搜索系统包含文件的路径。


建议:如果文件X包含文件Y,请使用#include" Y"如果Y是与X相同的程序或库的一部分。如果Y属于一个单独的库,请使用

#include< Yand如果需要,将编译器设置调整为包括那个

库。


Uli

There are two answers to this, one as given by the C and C++ language
standards and one that applies in reality.

1. The language defines several so-called headers like <stdio.h(C) or
<iostream(C++). These are not ever required to be files at all, it is
only required to have certain effects if you include them. In reality, most
compilers install these headers as part of the compiler installation.

2. In practice, you will find in the same dir as other compiler-supplied
headers are installed in also some files that are system-dependent.
Further, often libraries install their header files in that dir or add a
directory with their headers to the path searched for system include files.

Suggestion: if file X includes file Y, use #include "Y" if Y is part of the
same program or library as X. If Y belongs to a separate library, use
#include <Yand if necessary adjust the compiler settings to include that
library.

Uli


这篇关于如何确定“#include&lt; .....&gt;”的目录。获取头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆