【问题标题】:What are the differences between #include <filename> and #inlude "filename" specific to LLVM/Clang?特定于 LLVM/Clang 的 #include <filename> 和 #inlude "filename" 之间有什么区别?
【发布时间】:2014-02-06 22:13:13
【问题描述】:
【问题讨论】:
标签:
c++
objective-c
c
clang
llvm
【解决方案1】:
我在文档中找不到指定每种情况下预期行为的任何内容,所以我很好奇并决定查看here 中的代码。假设这就是它的行为方式可能是错误的,但是如果没有文档,我猜源代码是下一个最好的东西。
搜索代码我发现#include 编译指示在HandlePragmaDependency 方法(第453 行)中处理here,它确定是否包含isAngled(第468 行),然后使用它value 作为 LookupFile() 方法的参数(第 477 行)。
此方法在 HeaderSearch.cpp(第 498 行)中定义,其文档注释指出:
[...] isAngled 指示文件引用是否用于系统#include's
或不(即使用 而不是“”)。 [...]
稍后在该方法中,isAngled 的值用于三个地方(第 547、596 和 673 行),每个地方都有以下 cmets。
// Unless disabled, check to see if the file is in the #includer's
// directory. This cannot be based on CurDir, because each includer could be
// a #include of a subdirectory (#include "foo/bar.h") and a subsequent
// include of "baz.h" should resolve to "whatever/foo/baz.h".
// This search is not done for <> headers.
if (!Includers.empty() && !isAngled && !NoCurDirSearch) {
...
// If this is a system #include, ignore the user #include locs.
unsigned i = isAngled ? AngledDirIdx : 0;
...
// If we are including a file with a quoted include "foo.h" from inside
// a header in a framework that is currently being built, and we couldn't
// resolve "foo.h" any other way, change the include to <Foo/foo.h>, where
// "Foo" is the name of the framework in which the including header was found.
if (!Includers.empty() && !isAngled &&
Filename.find('/') == StringRef::npos) {
希望对你有帮助。
【解决方案2】:
语法:
#include < filename >(1)
#include "filename"(2)
说明
将由文件名标识的源文件包含到当前源文件中紧跟指令之后的行中。
1) 以实现定义的方式搜索文件。此语法的目的是搜索实现控制下的文件。典型实现仅搜索标准包含目录。标准 C++ 库和标准 C 库隐式包含在这些标准包含目录中。标准的包含目录通常可以由用户通过编译器选项来控制。
2) 以实现定义的方式搜索文件。此语法的目的是搜索不受实现控制的文件。典型的实现首先搜索当前文件所在的目录,只有在没有找到文件时才搜索标准的包含目录,如(1)。
【讨论】:
-
请不要抄袭other sources 的内容并将其作为您自己的答案发布,而不给予任何信任。无论如何,这并不能回答问题,因为该问题询问的是特定编译器,而您从中复制的文档仅说明了标准中的内容。