问题是 gflag 的 BUILD 文件包含它自己的配置。添加-H
到 glog.BUILD 的copts
产量:
. external/glog_archive/src/utilities.h
.. external/glog_archive/src/base/mutex.h
... bazel-out/local-fastbuild/genfiles/external/com_github_gflags_gflags/config.h
In file included from external/glog_archive/src/utilities.h:73:0,
from external/glog_archive/src/utilities.cc:32:
external/glog_archive/src/base/mutex.h:147:3: error: #error Need to implement mutex.h for your architecture, or #define NO_THREADS
# error Need to implement mutex.h for your architecture, or #define NO_THREADS
^
如果您查看 gflag 的 config.h,它采用了一种不太有用的方法来注释掉大部分配置:
// ---------------------------------------------------------------------------
// System checks
// Define if you build this library for a MS Windows OS.
//cmakedefine OS_WINDOWS
// Define if you have the <stdint.h> header file.
//cmakedefine HAVE_STDINT_H
// Define if you have the <sys/types.h> header file.
//cmakedefine HAVE_SYS_TYPES_H
...
所以什么都没有定义。
选项:
最简单的方法可能是在您的 glog.BUILD 中生成 config.h:
genrule(
name = "config",
outs = ["config.h"],
cmd = "cd external/glog_archive; ./configure; cd ../..; cp external/glog_archive/src/config.h $@",
srcs = glob(["**"]),
)
# Then add the generated config to your glog target.
cc_library(
name = "glog",
srcs = [...],
hdrs = [
":config.h",
...
这将 .h 文件置于比 gflags 版本更高的优先级位置。
或者,如果您想使用您的//third_party/glog/config.h
(@//
是项目存储库的简写),您可以在 genrule 中执行类似的操作:
genrule(
name = "config",
outs = ["config.h"],
cmd = "cp $(location @//third_party/glog:config.h) $@",
srcs = ["@//third_party/glog:config.h"],
)
您也必须添加exports_files(['config.h'])
到third_party/glog/BUILD
文件中。