在我的macOS系统上,我安装了以下内容:
brew install protobuf@3.14
brew install gcc@10
经 10.2.0_4
当我查看谷歌的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 找到了文件/usr/local/include/google/protobuf/any.h。我希望它能找到文件src/google/protobuf/any.h,因为该文件存在,并且我传递了-isystem src。自3.14.0版本以来,私有函数InternalPackFrom的签名发生了变化,因此出现了错误。
另外,当我尝试用clang++替换g++-10时,我获得了一个成功的构建。(我的印象是,克郎努力争取国旗与GCC的兼容):
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标志?
发布于 2021-02-25 22:15:29
结合Anton Malyshev和Ave Milia的回答/评论,明显的原因是苹果的自定义clang++版本(安装XCode时安装的)总是在系统开始时插入/usr/local/include包括路径列表,而不是任何其他条目,包括在命令行上传递的-isystem选项。(这可能是个bug)。您可以通过运行
clang++ -isystem /tmp -Wp,-v -E -注意到这些台词
#include <...> search starts here:
/usr/local/include
/tmp在输出中。
上游的clang++和g++都没有这种行为,所以这是苹果设计的一个怪癖。
要解决此问题,可以使用Homebrew安装llvm:
brew install llvm然后,按照下面的指令输出,将Homebrew的clang++放到您的路径上
brew link llvm发布于 2021-02-23 02:10:18
这不是因为-isystem src。出现此问题是因为clang++在其标准包含目录列表中包含路径/usr/local/include,而g++没有。
您可以使用以下命令检查标准包含目录的列表:
clang++ -nostdlib -Wp,-v -E -
g++-10 -Wp,-v -E -
为了避免包含/usr/local/include/google/protobuf/any.h by clang++,您可以删除文件或使用-nostdinc和-nostdinc++标志,并手动传递旧的包含目录。
https://stackoverflow.com/questions/66325376
复制相似问题