[英]CMake project that consumes dependencies built from a Bazel project
我有一個使用 glog(取決於 gflags)的簡單 Bazel 項目。
# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
)
http_archive(
name = "com_github_google_glog",
sha256 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022",
strip_prefix = "glog-0.6.0",
urls = ["https://github.com/google/glog/archive/v0.6.0.zip"],
)
# BUILD
cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [
"@com_github_google_glog//:glog",
]
)
# main.cpp
#include <glog/logging.h>
int main() {
LOG(INFO) << "Hello, World!";
return 0;
}
當我運行bazel build main
時,這會成功構建二進制文件。 我想在一個CMake項目中使用這個Bazel項目構建的glog + gflags依賴包含目錄和庫文件(原因有幾個這里就不細說了)。
有沒有辦法做到這一點? 我開始部分嘗試包含 Bazel build output 中的目錄,但遇到了編譯錯誤。
cmake_minimum_required(VERSION 3.20)
project(btest)
set(CMAKE_CXX_STANDARD 14)
include_directories(/path/to/bazel-out/darwin-fastbuild/bin/external/com_github_google_glog/_virtual_includes/glog)
include_directories(/path/to/bazel-out/darwin-fastbuild/bin/external/com_github_gflags_gflags/_virtual_includes/gflags)
add_executable(main main.cpp)
但是,這會產生如下錯誤:
In file included from ../main.cpp:1:
/path/to/bazel-out/darwin-fastbuild/bin/external/com_github_google_glog/_virtual_includes/glog/glog/logging.h:122:17: error: incomplete type in call to object of type 'struct GLOG_EXPORT'
LogMessageTime();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.