为什么没有针对grpc的预编译c ++库 [英] why there is no precompiled c++ library for grpc
问题描述
我正在尝试将grpc集成到C ++项目中.但是我发现唯一的方法是下载所有源代码并自行编译.
I'm trying to integrate grpc into C++ projects. but I found the only way is download all source code and compile it by my self.
有什么方法可以获取预编译的.so/.a文件(可以链接到该文件)和grpc_cpp_plugin(适用于Linux)吗?
Is there any way to get a precompile .so/.a file which I can link against and a grpc_cpp_plugin for Linux?
或者c ++不可能这样做,为什么?
Or is it impossible for c++ to do so and why?
推荐答案
如果您正在寻找预编译的gRPC库,则应使用 vcpkg ,我做到了这一点. 只需执行以下几个步骤即可:
If you are looking for precompiled gRPC libraries you should go with vcpkg. I was also trying to cross compile gRPC, without building the library itself. With vcpkg I achieved this quite well. There are just a few steps to set this up:
- 从GitHub中拉出vcpkg并按照说明进行设置
- 使用" ./vcpkg install grpc " 安装grpc.
- 将 CMakeLists.txt 中的CMAKE_TOOLCHAIN_FILE设置为vcpkg文件夹中的" vcpkg.cmake "文件
- 在您的 CMakeLists.txt 中添加gRPC
- Pull vcpkg from GitHub and follow the instructions to set it up
- Install grpc with "./vcpkg install grpc"
- Set CMAKE_TOOLCHAIN_FILE in your CMakeLists.txt to the "vcpkg.cmake"-file in your vcpkg-folder
- Add gRPC in your CMakeLists.txt
这是我的CMakeLists.txt:
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
else()
set(CMAKE_TOOLCHAIN_FILE "/path_to_vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()
project(Foo)
find_package(gRPC CONFIG REQUIRED)
...
add_executable(${PROJECT_NAME} ${Bar})
target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet)
在文件夹 path_to_vcpkg/packages/grpc_x64-PLATFORM/tools/grpc 中,您会找到适用于您平台的所有预编译grpc插件(也 grpc_cpp_plugin ).
In the Folder path_to_vcpkg/packages/grpc_x64-PLATFORM/tools/grpc you will find all the precompiled grpc-plugins for your platform (also grpc_cpp_plugin).
优点:
- 易于设置
- vcpkg可用于所有常见平台
- 如果不再需要软件包,则只需删除" path_to_vcpkg/packages "中的文件夹
- 包括您需要的所有gRPC工具
- easy to set up
- vcpkg is available for all common plattforms
- if a package isn't needed anymore you can just delete the folder in "path_to_vcpkg/packages"
- includes all the gRPC tools you need
缺点:
- 安装某些软件包后," path_to_vcpkg/packages "文件夹变得很大
- the "path_to_vcpkg/packages" folder gets quite big after some packages installed
这篇关于为什么没有针对grpc的预编译c ++库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!