在哪里包含存储的文件 - Ubuntu Linux,GCC [英] Where are include files stored - Ubuntu Linux, GCC

查看:128
本文介绍了在哪里包含存储的文件 - Ubuntu Linux,GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,当我们做以下事情时:

  #include< stdio.h> 



  #includemyFile.h

编译器,GCC在我的情况下,知道哪里stdio.h(甚至是目标文件)位于我的硬盘上。它只是利用了我没有交互的文件。



我认为在我的Ubuntu Linux机器上,文件存储在的/ usr /包括/ 编译器如何知道在哪里查找这些文件?这是可配置还是仅仅是预期的默认值?我在哪里寻找这个配置?



由于我对这些包含文件提出了一个问题,文件的来源是什么?我知道在Linux社区中这可能是模糊的,但谁来管理这些?谁会为Windows编译器提供和管理相同的文件。



我总是感觉他们 带有编译器,但那是假设...

解决方案

请参阅: Search Path b $ b

  #include  

当包含文件位于括号中时,预处理器首先在通过 -I 标志。然后它搜索标准的包含路径(请参阅上面的链接,并使用 -v 标志在您的系统上测试)。

  #includemyFile.h

当include文件在引号预处理器首先在当前目录中搜索,然后搜索由 -iquote -I 路径和标准路径指定的路径。



-nostdinc 可用于防止预处理器根本搜索标准路径。

环境变量也可用于添加搜索路径。



如果使用 -v 标志进行编译,则可以看到使用的搜索路径。


So, when we do the following:

#include <stdio.h>

versus

#include "myFile.h"

the compiler, GCC in my case, knows where that stdio.h (and even the object file) are located on my hard drive. It just utilizes the files with no interaction from me.

I think that on my Ubuntu Linux machine the files are stored at /usr/include/. How does the compiler know where to look for these files? Is this configurable or is this just the expected default? Where would I look for this configuration?

Since I'm asking a question on these include files, what are the source of the files? I know this might be fuzzy in the Linux community but who manages these? Who would provide and manage the same files for a Windows compiler.

I was always under the impression that they come with the compiler but that was an assumption...

解决方案

See here: Search Path

Summary:

#include <stdio.h>

When the include file is in brackets the preprocessor first searches in paths specified via the -I flag. Then it searches the standard include paths (see the above link, and use the -v flag to test on your system).

#include "myFile.h"

When the include file is in quotes the preprocessor first searches in the current directory, then paths specified by -iquote, then -I paths, then the standard paths.

-nostdinc can be used to prevent the preprocessor from searching the standard paths at all.

Environment variables can also be used to add search paths.

When compiling if you use the -v flag you can see the search paths used.

这篇关于在哪里包含存储的文件 - Ubuntu Linux,GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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