cmake - 没有使用 Cmake protobuf 制作目标的规则
问题描述
我正在尝试让 Cmake 编译我的原型文件。为此,我使用以下 CMakeLists.txt。
include(FindProtobuf)
find_package(Protobuf REQUIRED)
# check if protobuf was found
if(PROTOBUF_FOUND)
message ("protobuf found")
else()
message (FATAL_ERROR "Cannot find Protobuf")
endif()
include_directories(${PROTOBUF_INCLUDE_DIR})
message(${PROTOBUF_INCLUDE_DIR})
set(PROTO_FILES
msg.proto)
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER ${PROTO_FILES})
message ("PROTO_SRC = ${PROTO_SRC}")
message ("PROTO_HEADER = ${PROTO_HEADER}")
add_library(proto ${PROTO_HEADER} ${PROTO_SRC})
我的文件夹结构:
cpp/
protos
msg.proto
CMakeLists.txt
build
debug
我从构建/调试构建。找到了 Protobuf。对于 Proto_src 和 Proto_header 我发现:
PROTO_SRC = /home/mike/code/protos/cpp/build/debug/protos/msg.pb.cc
PROTO_HEADER = /home/mike/code/protos/cpp/build/debug/protos/msg.pb.h
但是在尝试编译时出现以下错误:
make[2]: *** No rule to make target '../../protos/msg.proto', needed by 'protos/msg.pb.h'. Stop.
我从https://github.com/shaochuan/cmake-protobuf-example获得了设置
我没有看到我在这里缺少什么?
解决方案
推荐阅读
- php - 如何在 mac osx 10.11 El Capitan 上安装 php 7.4 版?
- java - 使用单选按钮和两个活动更改图像视图
- arduino - 如何在 arduino-due 上使用选定地址写入/读取 arduino 闪存
- nginx - 将 nginx 配置为域访问 react app 子路径路由
- r - R - 从在线数据库中提取数据并为每次迭代具有唯一名称的循环脚本
- css - 将两个块之间的链接居中并使文本变为白色/ css
- c# - 将 JSON 响应反序列化为特定的类对象
- kotlin - 如何在房间数据库kotlin中保存数字
- c++ - 同时读取和写入不同的文件 - 多线程有用吗?
- python - 等到在python中满足所需的条件