【发布时间】:2021-05-25 06:23:45
【问题描述】:
在我的 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。自 3.14.0 版本以来,私有函数 InternalPackFrom 的签名已更改,因此出现错误。
另外,当我尝试用g++-10 替换clang++ 时,我得到了一个成功的构建。 (我的印象是 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 标志?
【问题讨论】:
标签: c++ macos clang++ include-path