我正在尝试使用gRPC库,但是我不断收到错误消息,告诉我它找不到.cmake文件,或者出现链接器错误,这可能是由于我的CMakeLists.txt所致。在examples I'm following中,他们将cmake中的库简称为gRPC,我也尝试过关键字grpc_cpp_plugin,但是似乎都没有用。
对于上下文,我正在使用macOS Mojave,并且已经使用自制软件安装了gRPC库。
Homebrew在/usr/local/Cellar/grpc/1.22.0
中安装了gRPC库。
我在这里使用了一个适用于另一个项目的cmake文件,但是我已经在protobuf和gRPC库中添加了它们,并且在添加它们之后才出现错误。再次从上面的链接中借用了一些代码(特别是gRPC文件所在的名称)。
我的CMakeLists.txt文件
cmake_minimum_required( VERSION 2.8 )
project( gRPC_server )
# setup opencv
find_package( OpenCV REQUIRED )
# SETUP PROTOBUF
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package( Protobuf REQUIRED )
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
# SETUP GRPC
find_package( gRPC REQUIRED )
set(_GRPC_GRPCPP_UNSECURE gRPC::grpc++_unsecure)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
# mostly just to set it to the correct compiler
SET(CMAKE_CXX_FLAGS "-std=c++0x -Wall -g -Werror")
add_executable( server server.cpp compiled/image.grpc.pb.cc compiled/image.pb.cc )
target_link_libraries( server ${OpenCV_LIBS} ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF} )
add_executable( client client.cpp compiled/image.grpc.pb.cc compiled/image.pb.cc )
target_link_libraries( client ${OpenCV_LIBS} ${_GRPC_GRPCPP_UNSECURE} ${_PROTOBUF_LIBPROTOBUF} )
特别奇怪的是,错误消息没有意义
-- Found OpenCV: /opt/local (found version "3.4.3")
-- Found Protobuf: /usr/local/lib/libprotobuf.a (found version "3.7.0")
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindgRPC.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "gRPC", but
CMake did not find one.
Could not find a package configuration file provided by "gRPC" with any of
the following names:
gRPCConfig.cmake
grpc-config.cmake
Add the installation prefix of "gRPC" to CMAKE_PREFIX_PATH or set
"gRPC_DIR" to a directory containing one of the above files. If "gRPC"
provides a separate development package or SDK, be sure it has been
installed.
如果我注释掉gRPC内容,则会出现链接器错误。
感谢您的任何帮助,谢谢!
您必须通过pkg-config找到gRPC。它已在gRPC C ++ QuickStart中声明。
示例cmake代码:
find_package(PkgConfig REQUIRED)
pkg_search_module(GRPC REQUIRED grpc)
pkg_search_module(GRPCPP REQUIRED grpc++>=1.22.0)
我在自己的tensorflow-serving-client存储库中使用它们。