本文介绍了使用预安装的软件包从源代码构建grpc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将gRPC集成到现有项目中.它已经有包含所有gRPC依赖项安装目录(ssl,c-ares,protobuf和zlib).我想在构建gRPC时使用它们,并将gRPC安装到同一目录中.我下载了gRPC存档(不克隆位于grpc/third_party/中的子模块),并尝试生成用于将gRPC生成并安装到目标文件夹中的生成系统(使用cmake).

I'm trying to integrate gRPC in existing project. It already has directory containing all gRPC's dependencies installed (ssl, c-ares, protobuf and zlib). I want to use them while building gRPC, and install gRPC into the same directory.I downloaded gRPC archive (without cloning submodules located in grpc/third_party/), and tried to generate build system for building and installing gRPC into my destination folder (using cmake).

我使用了以下命令:

cmake -DCMAKE_INSTALL_PREFIX=$PREFIX -DgRPC_ZLIB_PROVIDER=package -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DgRPC_CARES_PROVIDER=package

出现错误:

CMake Error at cmake/cares.cmake:34 (find_package):
Could not find a package configuration file provided by "c-ares" with any
of the following names:

c-aresConfig.cmake
c-ares-config.cmake
Add the installation prefix of "c-ares" to CMAKE_PREFIX_PATH or set
"c-ares_DIR" to a directory containing one of the above files.  If "c-ares"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:116 (include)
-- Configuring incomplete, errors occurred!

我有1.14.0版的c-ares(来自 https://c-ares.haxx. se/),它是使用

I have c-ares of version 1.14.0 (from https://c-ares.haxx.se/), it is built using

./configure --prefix=$PREFIX
make && make install

,它不提供上述任何文件(c-aresConfig.cmake,c-ares-config.cmake).

and it doesn't provide any of the above files (c-aresConfig.cmake, c-ares-config.cmake).

我尝试从github获取c-ares并使用cmake进行构建,并成功了:请求的文件出现在安装目录中,因此gRPC构建系统已成功生成.

I tried to get c-ares from github and to build it using cmake, and have succeed: requested files appeared in installation directory, so gRPC build system was generated successfully.

我的问题是:我可以在不将c-ares更新为github-version的情况下构建和安装gRPC吗?

My question is: can I build and install gRPC without updating c-ares to github-version?

如果这不容易完成,也许可以通过某种方式禁用gRPC中的c-ares的使用(改为使用本机dns解析器)?

If this can't be done easily, maybe it is possible to disable usage of c-ares in gRPC somehow (use native dns resolver instead)?

推荐答案

c-ares有两个正在使用的构建系统,即CMake和自动工具.它两者都支持,但是您需要选择一个.自动工具的存在时间更长,并且是UNIX环境中传统上使用的一种.来自Linux发行版的c-ares的二进制软件包将使用自动工具,例如如果您dnf install c-ares-devel,您将获得基于自动工具的c-ares版本.

c-ares has two build systems that are being used here, CMake and autotools. It supports both, but you need to choose one. The autotools one has been around longer and is the one traditionally used in UNIX environments. Binary packages of c-ares from Linux distros will use autotools, e.g. if you dnf install c-ares-devel, you'll get an autotools based build of c-ares.

自动工具生成系统将安装pkgconfig文件libcares.pc,以提供有关如何使用c-ares的信息. CMake系统将安装c-ares-config.cmake来执行此操作.

The autotools build system installs a pkgconfig file, libcares.pc, to provide information about how to use c-ares. The CMake system installs c-ares-config.cmake to do this.

所以这里的问题是您正在使用自动工具构建c-ares,但是gRPC仅考虑了使用CMake构建c-ares的可能性.

So the problem here is that you are building c-ares with autotools but gRPC only considered the possibility that CMake would have been used to build c-ares.

因此,您可以切换到使用CMake构建c-ares或修补gRPC,以为c-ares提供更好的查找模块,该模块可与pkgconfig文件一起使用. CMake支持pkgconfig文件,因为它们在CMake存在之前就已经被广泛使用并且仍然被广泛使用,因此后者并不难.

So you can either switch to building c-ares with CMake or patch gRPC to have a better find module for c-ares that works with pkgconfig files. CMake supports pkgconfig files, as they were widely used before CMake existed and still are widely used, so the latter is not that hard.

或者,在为gRPC运行cmake时尝试定义-D_gRPC_CARES_LIBRARIES=cares-DgRPC_CARES_PROVIDER=kludge.这会使gRPC CMake代码伪装成不寻找c-ares,并假设"-lcares"会找到它.

Or, trying defining -D_gRPC_CARES_LIBRARIES=cares and -DgRPC_CARES_PROVIDER=kludge when running cmake for gRPC. This fakes out the gRPC CMake code into not looking for c-ares and assuming that "-lcares" will find it.

这篇关于使用预安装的软件包从源代码构建grpc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 19:34