【问题标题】:protobuf_generate grpc_cpp_plugin fails with status code 1protobuf_generate grpc_cpp_plugin 失败,状态码为 1
【发布时间】:2021-03-12 23:32:34
【问题描述】:

我正在尝试生成 grpc cpp 文件,但是当我在 cmake 中调用它时生成器插件失败

find_package(protoc CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) #get plugin location
get_target_property(protoc_location protobuf::protoc LOCATION) #for sanity check
message("protoc is at ${protoc_location}") #for sanity check
message("grpc plugin is at ${grpc_cpp_plugin_location}") #for sanity check
add_library(${PRO_NAME} ${PRO_SRCS} test.proto)

protobuf_generate(TARGET ${PRO_NAME} LANGUAGE cpp)
protobuf_generate(TARGET ${PRO_NAME} LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")

产生类似的错误

protoc is at /home/user/.conan/data/protoc_installer/...
grpc plugin is at /home/user/.conan/data/grpc/...
-- Configuring done
-- Generating done
-- Build files have been written to: 
[ 16%] Running grpc protocol buffer compiler on test.proto
protoc-gen-grpc: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1

但是如果我在 shell 脚本中手动使用它,即使我从 cmake 输出复制文件路径,它也可以工作

PROTOC=${PATH FROM CMAKE}
GRPCC=${PATH FROM CMAKE}
$PROTOC -I src/ --grpc_out=. --plugin=protoc-gen-grpc=$GRPCC test.proto

基于https://www.falkoaxmann.de/dev/2020/11/08/grpc-plugin-cmake-support.html的方法

我最初认为我的问题是库路径错误,我正在使用带有柯南导入管理的远程构建服务器,但我验证了插件 rpath 包含它需要的库的相对位置。

【问题讨论】:

  • protoc-gen-grpc 是否在您的$PATH 的文件夹中?
  • @PaulSanders 不,它在包管理器下载的文件夹中,所以我不能相信它在任何特定的地方。为了在 cli 中运行它,我使用了它的完整路径,但我从 cmake 找到它的路径复制了它。
  • 您可以尝试将该文件的副本放在路径中的文件夹中 - 比如说 /usr/local/bin
  • 您可能遇到与github.com/faaxm/exmpl-cmake-grpc/issues/1相同的问题。

标签: c++ cmake grpc conan protoc


【解决方案1】:

问题可能是 cmake 使用了过时的 protobuf 配置,或者更确切地说是 cmake 附带的 FindProtobuf.cmake 而不是 protobuf 包附带的 ProtobufConfig.cmake

要解决此问题,请自行编译 gRPC,并在为 gRPC 运行 cmake 时使用 -DgRPC_PROTOBUF_PACKAGE_TYPE=CONFIG 标志。

问题来自 gRPC 在其 gRPCConfig.cmake 中有自己的 find_package(Protobuf) 调用,取决于 gRPC_PROTOBUF_PACKAGE_TYPE,它可能在 MODULE 模式下运行。 (在模块模式下,它会找到旧的 FindProtobuf.cmake)

查看最近添加的 github 工作流,以获取有关如何构建依赖项的示例和示例: https://github.com/faaxm/exmpl-cmake-grpc/blob/master/.github/workflows/build.yml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 2012-10-17
    相关资源
    最近更新 更多