glog 在预处理器表达式“@”的开头抛出无效标记
glog throws invalid token at start of a preprocessor expression '@'
我在工作区中使用 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 编译器的问题吗?
正在写答案以便我可以格式化。你可以试试这里的例子 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;
}
这是 glog 中的一个错误,由 https://github.com/google/glog/pull/291
解决
我在工作区中使用 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 编译器的问题吗?
正在写答案以便我可以格式化。你可以试试这里的例子 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;
}
这是 glog 中的一个错误,由 https://github.com/google/glog/pull/291
解决