0

我在工作区中使用 Bazel 将 glog 导入为:

git_repository(
    name = "com_github_glog_glog",
    commit = "3106945d8d3322e5cbd5658d482c9ffed2d892c0",
    remote = "https://github.com/google/glog.git",
)

bind(
    name = "glog",
    actual = "@com_github_glog_glog//:glog",
)

当直接构建 glog(bazel build external:glog)时,它工作正常,但是,当我尝试将它用作我的一个构建目标中的依赖项时,我收到以下错误:

bazel-out/darwin-fastbuild/bin/external/com_github_glog_glog/_virtual_includes/glog/glog/stl_logging.h:50:6: error: invalid token at start of a preprocessor expression
#if !@ac_cv_cxx_using_operator@
     ^

我在 macOS 10.13.2 上。

关于如何解决这个问题的任何想法?macOS上的编译器有问题吗?

4

2 回答 2

0

写答案,以便我可以格式化。如果这里的示例https://github.com/google/glog/tree/master/bazel/example适合您,您可以试试吗?我在linux上顺利编译:

工作空间:

git_repository(
    name = "com_github_glog_glog",
    commit = "3106945d8d3322e5cbd5658d482c9ffed2d892c0",
    remote = "https://github.com/google/glog.git",
)

http_archive(
    name = "com_github_gflags_gflags",
    sha256 = "6e16c8bc91b1310a44f3965e616383dbda48f83e8c1eaa2370a215057b00cabe",
    strip_prefix = "gflags-77592648e3f3be87d6c7123eb81cbad75f9aef5a",
    urls = [
        "https://mirror.bazel.build/github.com/gflags/gflags/archive/77592648e3f3be87d6c7123eb81cbad75f9aef5a.tar.gz",
        "https://github.com/gflags/gflags/archive/77592648e3f3be87d6c7123eb81cbad75f9aef5a.tar.gz",
    ],
)

bind(
    name = "glog",
    actual = "@com_github_glog_glog//:glog",
)

建造

cc_library(
    name = "foo",
    srcs = [ "foo.cc" ],
    deps = [ "@com_github_glog_glog//:glog" ],
)

foo.cc

#include <gflags/gflags.h>
#include <glog/logging.h>

int main(int argc, char* argv[]) {
  // Initialize Google's logging library.
  google::InitGoogleLogging(argv[0]);

  // Optional: parse command line flags
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  LOG(INFO) << "Hello, world!";

  return 0;
}
于 2018-01-31T13:26:54.757 回答
0

这是 glog 中的一个错误,由https://github.com/google/glog/pull/291解决

于 2018-03-01T06:59:32.603 回答