gpt4 book ai didi

clang - clang 的包含优先级是怎么回事?

转载 作者:行者123 更新时间:2023-12-01 03:51:32 27 4
gpt4 key购买 nike

我的命令:

/usr/bin/c++ -fPIC -I/Users/me/project/include -I/usr/local/include/opencv \
-I/usr/local/include -I/opt/local/include -std=c++11 -O3 -M -c \
/Users/me/project/src/program.cpp | grep opencv
program.cpp已:
#include "opencv2/core/core.hpp"
#include "opencv2/ml/ml.hpp"

输出:
  /opt/local/include/opencv2/core/core.hpp \
/opt/local/include/opencv2/core/types_c.h /usr/include/assert.h \
/usr/include/math.h /opt/local/include/opencv2/core/version.hpp \
/opt/local/include/opencv2/core/operations.hpp \
/opt/local/include/opencv2/core/mat.hpp \
/opt/local/include/opencv2/objdetect/objdetect.hpp \
/opt/local/include/opencv2/ml/ml.hpp \

但是,存在: /usr/local/include/opencv2/core/core.hpp , 和 /usr/local/include/opencv2/ml/ml.hpp .

使用 -v旗帜,叮当告诉我:
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/Users/me/project/include
/usr/local/include/opencv
/opt/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)

为什么 clang 包括来自 /opt/local/include而不是 /usr/local/include ,尽管 /usr/local/include-I 列表中排在第一位命令中的目录?为什么是 /usr/local/include下推优先级列表。

最佳答案

您可以检查 #include 的默认搜索路径经过:

gcc -Wp,-v -E -

(给预处理器 -v 标志)。

您的目录(以 -I 给出)在标准列表之前按您提供的顺序进行搜索。

你给 /usr/local/include明确地,和 gcc无视您的指令,因为它稍后会被添加(作为系统目录);因此以错误的顺序搜索目录。如果你真的想控制自己搜索的目录,使用 -nostdinc并全部给他们。那是极其脆弱的。

拥有两组同名的头文件是一个非常糟糕的主意(正如您所发现的)。没有办法清理那个烂摊子吗?

关于clang - clang 的包含优先级是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22178946/

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