这个报错是因为 macOS 系统不支持 thread-local storage,而 Bazel 在编译时需要使用该功能。解决方法如下:
1.升级你的 macOS 版本到最新版本。
2.使用 Docker 环境运行 Bazel 编译 Envoy。在 Docker 中,可以使用 Linux 系统进行编译,从而避免 macOS 不支持的问题。具体步骤可以参考官方文档 https://www.envoyproxy.io/docs/envoy/latest/start/building.html#building-with-docker
3.修改编译选项,禁用 thread-local storage。在 Envoy 的 BUILD 文件中,找到 cc_library
相关的规则,加上 --copt=-fno-threadsafe-statics
选项,例如:
cc_library(
name = "envoy_common",
srcs = [
...
],
hdrs = [
...
],
visibility = ["//visibility:public"],
deps = [
...
],
copts = [
"-fPIC",
"-std=c++14",
"-Wall",
"-Werror",
"--copt=-fno-threadsafe-statics", # 添加这一行
],
)
注意,这种方法可能会导致一些功能失效或出现其他问题,仅在无法使用其他方法时才考虑使用。