我有以下BUILD
文件:
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
### Protos ###
cc_proto_library(
name = "homework_cc_proto",
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)
proto_library(
name = "homework_proto",
srcs = [
"protos/complexity.proto",
"protos/example.proto",
"protos/problem.proto",
"protos/solution.proto",
],
)
### End Protos ###
### Binaries ###
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = [":homework_cc_proto"],
)
和
main.cc
:#include <iostream>
#include "example.pb.h"
int main() {
std::cout << "Hello!" << std::endl;
}
如果我调用
bazel build :homework_cc_proto
,则构建成功。但是,当我运行bazel build :main
时,出现一条错误消息,指出找不到example.pb.h
。如何导入我的内置protobuf? 最佳答案
您的cc_proto_library
需要依赖homework_proto
。
cc_proto_library(
name = "homework_cc_proto",
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
deps = [ ":homework_proto" ],
)