通过编译器更改#include指令处理 [英] Alter #include directive processing by compiler

查看:49
本文介绍了通过编译器更改#include指令处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS2013。 #include指令的默认行为如下所述:



预处理器按此顺序搜索包含文件:



  1. 与包含  #include 的文件位于同一目录中;声明。



  2. 在当前打开的包含文件的目录中,以相反的顺序打开它们。搜索从父包含文件的目录开始,并继续向上遍历任何祖父母包含文件的
    目录。



  3. 沿着每个/ I编译器选项指定的路径。



  4. 沿着INCLUDE环境变量指定的路径。



我想知道是否有任何编译器开关(或任何方式)禁用上述第二点,因为它会导致包含意外文件的问题。


谢谢。


解决方案

嗨chrat,


<感谢您在此处发帖。


>>我想知道是否有任何编译器开关(或任何方式)禁用上述第二点作为其导致包含意外文件的问题。


对于这种情况,如果你附上一个complet e,双引号之间的包含文件的明确路径规范(" "),预处理器仅搜索该路径规范并忽略标准目录。一旦找到具有给定名称的文件,预处理器就会停止
搜索。


在我看来,您遇到的问题不是由此编译器功能引起的。它们之所以发生是因为您包含
意外文件。


因此,请提供有关问题的详细信息,以便我们找到根本原因。


您对包含的意外文件的意思是什么?


您使用了错误的名称还是包含了不存在的头文件?


您的理解与合作将不胜感激。


最诚挚的问候,

Sera Yu


I am using VS2013. The default behaviour for #include directive is as described :

The preprocessor searches for include files in this order:

  1. In the same directory as the file that contains the #include statement.

  2. In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.

  3. Along the path that's specified by each /I compiler option.

  4. Along the paths that are specified by the INCLUDE environment variable.

I want to know if there is any compiler switch(or any way) to disable the 2nd point described above as its causing problems by including unexpected files.

Thanks.

解决方案

Hi chrat,

thanks for posting here.

>>I want to know if there is any compiler switch(or any way) to disable the 2nd point described above as its causing problems by including unexpected files.

For this case, if you enclose a complete, unambiguous path specification for the include file between double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories. The preprocessor stops searching as soon as it finds a file that has the given name.

In my opinion, the problems you face aren't caused by this compiler feature. They occur because you include unexpected files.

So please provide more information of your problem, so that we could find the root cause.

what do you mean of unexpected files you include?

Do you use the wrong name or do you include header files that don't exist?

Your understanding and cooperation will be grateful.

Best Regards,
Sera Yu


这篇关于通过编译器更改#include指令处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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