-I dir与-isystem dir [英] -I dir vs. -isystem dir

查看:165
本文介绍了-I dir与-isystem dir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想要包含要搜索头文件的目录,哪种方法是首选方法?为什么? 适用于-I 的gcc文档:


将目录dir添加到要搜索头文件的目录列表头部。这可以用来覆盖系统头文件,替换你自己的版本,因为这些目录是在系统头文件目录之前被搜索的。但是,您不应该使用此选项来添加包含供应商提供的系统头文件的目录(使用-isystem)。如果您使用多个-I选项,则按照从左到右的顺序扫描目录;如果标准系统包含目录或用-isystem指定的目录,则也使用-I指定,则-I选项将为忽略。该目录仍将被搜索,但作为系统目录在系统包含链中的正常位置。这是为了确保GCC的程序修复buggy系统头文件和include_next指令的顺序不会被无意中改变。如果您确实需要更改系统目录的搜索顺序,请使用-nostdinc和/或-isystem选项。

因此 -I 可能是指定您的位置的首选选项头文件,除了诸如供应商提供的系统头文件之类的特殊情况。


If I want to include directories to be searched for header files, which is the preferred way and why?

解决方案

From the gcc documentation for -I:

Add the directory dir to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files (use -isystem for that). If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come after.

If a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option will be ignored. The directory will still be searched but as a system directory at its normal position in the system include chain. This is to ensure that GCC's procedure to fix buggy system headers and the ordering for the include_next directive are not inadvertently changed. If you really need to change the search order for system directories, use the -nostdinc and/or -isystem options.

So -I is probably the preferred option to specify the location of your header files, except for special cases such as vendor-supplied system headers.

这篇关于-I dir与-isystem dir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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