首页 > 解决方案 > 没有使用 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获得了设置

我没有看到我在这里缺少什么?

标签: cmakeprotobuf-c

解决方案


推荐阅读