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

问题描述 投票:0回答:2

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

c++ macos bazel glog
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.曹操

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

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.