gpt4 book ai didi

c++ - 如何自定义clang的包含路径顺序?

转载 作者:行者123 更新时间:2023-12-03 07:39:15 25 4
gpt4 key购买 nike

问题
我可以使用 clang 8 自定义包含路径的顺序吗?
例如:
使用带有 -v 的 clang 编译项目标志,它将输出此类日志。

#include <...> search starts here:

Path1

Path2

Path3
如何将 Path3 移动到 Path2 之前?
有关此问题的详细信息如下。
背景
出于某种原因,我必须使用 clang v8.0 来使用 xcodebuild 编译我的项目。最近,我为我的项目添加了一些 C++ 代码(在 .mm 文件中),然后在构建代码时出现 fatal error 。
错误如下(出于隐私原因,我省略了文件路径):
...xxxxx.mm:16:10: fatal error: 'fstream' file not found
#include <fstream>
^~~~~~~~~
1 error generated.
似乎 Clang 找不到 C++ 头文件。 (不仅流,其他头文件也找不到)
为了比较,我用 Apple Clang 编译了这个项目和 -v标志,然后它工作正常。我比较了这两个版本的日志输出。 Clang 8 不包括 /Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include进入其标题搜索路径。然后我设置 HEADER_SEARCH_PATHS值(value)与 /Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1我重新编译它,然后我得到另一个错误:
In file included from <module-includes>:1:
/Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctype.h:38:15: fatal error: cyclic dependency in module 'Darwin':
Darwin -> std -> Darwin
#include_next <ctype.h>
这似乎包含路径顺序导致 C++ 头文件中的循环依赖。所以我比较了apple clang 下的输出和本例中的输出。我发现它们的包含路径顺序之间存在微小差异:
Apple Clang (编译成功)
#include <...> search starts here:
...xxxxx.hmap (headermap)

...xxxxx.hmap (headermap)
/Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/Applications/Xcode11.7.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk/usr/include
/Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode11.7.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk/System/Library/Frameworks (framework directory)
Clang 8(编译失败)
#include <...> search starts here:
...xxxxx.hmap (headermap)

...xxxxx.hmap (headermap)

/Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
...xxx/clang/8.0.0/include
/Applications/Xcode11.7.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk/usr/include
/Applications/Xcode11.7.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk/System/Library/Frameworks (framework directory)
如果 ...XcodeDefault.xctoolchain/usr/include在这个包含路径列表的倒数第二个位置,它会起作用。
那么,我怎样才能将它移动到倒数第二个位置呢?还是我的编译过程有其他问题?

最佳答案

我已经通过以下方式解决了这个问题:

export CPLUS_INCLUDE_PATH=/Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

关于c++ - 如何自定义clang的包含路径顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65166151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com