glog在预处理器表达式'@'的开头抛出无效标记

时间:2018-01-29 01:14:33

标签: c++ macos bazel glog

我在工作区中使用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上编译器的问题吗?

2 个答案:

答案 0 :(得分:0)

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

WORKSPACE:

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",
)

BUILD

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;
}

答案 1 :(得分:0)

这是由https://github.com/google/glog/pull/291

解决的glog中的错误