c++ - clang++ 不尊重 -isystem 标志,与 g++ 不同的行为
问题描述
在我的 macOS 系统上,我安装了以下内容:
- Protobuf 3.14.0 通过
brew install protobuf@3.14
- g++ 10.2.0_4 通过
brew install gcc@10
- clang++ 1200.0.32.29 通过 XCode
当我查看 Google 的 Protobuf 存储库并使用 构建文件clang++
时,它似乎忽略了-isystem
我传递的标志:
git clone https://github.com/protocolbuffers/protobuf.git && cd protobuf && git checkout 326ea555b
clang++ -std=c++17 -isystem src -c src/google/protobuf/any_lite.cc
这给出了一个错误:
src/google/protobuf/any_lite.cc:56:19: error: return type of out-of-line definition of 'google::protobuf::internal::AnyMetadata::InternalPackFrom' differs from that in the declaration
bool AnyMetadata::InternalPackFrom(const MessageLite& message,
~~~~ ^
/usr/local/include/google/protobuf/any.h:108:8: note: previous declaration is here
void InternalPackFrom(const MessageLite& message,
~~~~ ^
1 error generated.
发生这种情况是因为#include <google/protobuf/any.h>
找到了文件/usr/local/include/google/protobuf/any.h
。我希望它能够找到该文件src/google/protobuf/any.h
,因为该文件存在并且我通过了-isystem src
。InternalPackFrom
自 3.14.0 版以来,私有函数的签名已更改,因此出现错误。
此外,当我尝试用 替换clang++
时g++-10
,我得到了成功的构建。(我的印象是 Clang 努力争取与 GCC 的 flag-for-flag 兼容性):
git clone https://github.com/protocolbuffers/protobuf.git && cd protobuf && git checkout 326ea555b
g++-10 -std=c++17 -isystem src -c src/google/protobuf/any_lite.cc
为什么clang++
忽略-isystem
这里的标志?
解决方案
那不是因为-isystem src
。出现问题是因为 clang++/usr/local/include
在其标准包含目录列表中包含路径,而 g++ 没有。
您可以使用以下命令检查标准包含目录的列表:
clang++ -nostdlib -Wp,-v -E -
g++-10 -Wp,-v -E -
为避免/usr/local/include/google/protobuf/any.h
被 clang++ 包含,您可以删除文件或使用-nostdinc
和-nostdinc++
标志并手动传递旧的包含目录。
推荐阅读
- java - JAXB:XmlSeeAlso 的 StackOverFlowError
- c++ - std::is_base_of 用于模板类(非类型模板参数)
- mysql - MySql中两个表的数据计数总和
- javascript - html 输入框在打印页面中未对齐
- bash - 获取 if 语句中的命令输出到变量中
- spring-boot - 如何调试 Spring Security Oath2 和 Jwt 以了解其工作原理
- ansible - 运行ansible playbook时遇到“无法访问”“权限被拒绝”错误
- java - 在 Eclipse 中使用正则表达式在 xml 文件中查找查询
- python - 为什么每个线程都得到一个新的 packageManager 对象副本?我怎么可以只用一个?
- azure-devops - ADO 项目的存档选项