grpc找不到protobuf libray [英] grpc can't find protobuf libray
问题描述
我完成了grpc的安装,并完成了构建和安装.
I went over the grpc installation and finished building and installation.
现在,当我尝试:
find_package(gRPC CONFIG REQUIRED)
我知道
CMake Error at CMakeLists.txt:15 (find_package):
Found package configuration file:
/usr/lib64/cmake/grpc/gRPCConfig.cmake
but it set gRPC_FOUND to FALSE so package "gRPC" is considered to be NOT
FOUND. Reason given by package:
The following imported targets are referenced, but are missing:
protobuf::libprotobuf protobuf::libprotoc
事件
find_package(Protobuf REQUIRED)
工作正常.
我读到我应该运行cmake ../.. -DBUILD_DEPS=ON -DBUILD_SHARED_LIBS=ON
来解决这个问题.但是,结果是:
I read I'm supposed to run cmake ../.. -DBUILD_DEPS=ON -DBUILD_SHARED_LIBS=ON
to solve this. However that results in:
CMake Error at cmake/abseil-cpp.cmake:38 (find_package):
Could not find a package configuration file provided by "absl" with any of
the following names:
abslConfig.cmake
absl-config.cmake
Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
"absl_DIR" to a directory containing one of the above files. If "absl"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:191 (include)
-- Configuring incomplete, errors occurred!
See also "/home/ray/CLionProjects/grpc/grpc/CMakeFiles/CMakeOutput.log".
See also "/home/ray/CLionProjects/grpc/grpc/CMakeFiles/CMakeError.log".
/usr/lib64/cmake/grpc/gRPCConfig.cmake的内容
Content of /usr/lib64/cmake/grpc/gRPCConfig.cmake
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
推荐答案
问题实际上出在您通过find_package()
使用的项目及其打包文件(在您的情况下为/usr/lib64/cmake/grpc/gRPCConfig.cmake
).错误消息
The problem is actually with the project you use via find_package()
and with its package file (/usr/lib64/cmake/grpc/gRPCConfig.cmake
in your case). The error message
The following imported targets are referenced, but are missing:
意味着,程序包文件引用了IMPORTED目标,但从未定义它们.
means, that the package file references IMPORTED targets but they are never defined.
该问题的通常原因如下:
The usual reason for that problem is following:
-
在其自身的构建过程中,项目将
find_package()
用于其他一些软件包.此find_package()
调用定义了IMPORTED目标,该目标在项目中用于链接.
During its own build, the project uses
find_package()
for some other packages. Thisfind_package()
call defines IMPORTED targets, which are used in the project for link.
它的软件包文件包含脚本,该脚本由install(EXPORT)
命令创建并根据install(TARGETS ... EXPORT ...)
命令填充.该包含的脚本使用IMPORTED目标,但未定义它们.
Its package file includes the script(s), which is created by install(EXPORT)
command and filled according to install(TARGETS ... EXPORT ...)
command. This included script uses IMPORTED targets, but doesn't define them.
项目的打包文件忘记了,以便使用find_package
,或者更好的是,使用
The project's package file forgets to use find_package
, or, better, find_dependency for define the IMPORTED target for the included scripts.
如果您不想修复(其他)项目的程序包文件,那么最直接的解决方案是将缺少的find_package
添加到您自己的项目中:
If you don't want to fix the (other) project's package file, then the most direct solution is to add missed find_package
into your own project:
# Hack: This will define IMPORTED targets, needed for gRPC project, but not defined by it.
find_package(Protobuf REQUIRED)
# Now perform the original 'find_package' call.
find_package(gRPC CONFIG REQUIRED)
实际上,gRPCConfig.cmake
软件包文件旨在包含调用find_package(Protobuf)
.其模板 cmake/gRPCConfig.cmake.in 是以下:
Actually, gRPCConfig.cmake
package file was intended to contain the call find_package(Protobuf)
. Its template cmake/gRPCConfig.cmake.in is following:
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
@_gRPC_FIND_ZLIB@
@_gRPC_FIND_PROTOBUF@
@_gRPC_FIND_SSL@
@_gRPC_FIND_CARES@
@_gRPC_FIND_ABSL@
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
,并且在替换时,变量_gRPC_FIND_PROTOBUF
应发出以下代码:
and on substitution the variable _gRPC_FIND_PROTOBUF
should emit the following code:
if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)
find_package(Protobuf ${gRPC_PROTOBUF_PACKAGE_TYPE})
endif()
(变量应在
但是出了点问题,结果/usr/lib64/cmake/grpc/gRPCConfig.cmake
包含空变量的替换:
But something goes wrong, and the resulted /usr/lib64/cmake/grpc/gRPCConfig.cmake
contains the empty variable's substitution:
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
这篇关于grpc找不到protobuf libray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!