热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

grpcgitee镜像编译

因为github被墙的厉害,gitclone很慢,grpcsubmodule还特别多,幸亏找到了gitee上的源,感谢git

因为github被墙的厉害,git clone很慢,grpc submodule还特别多,幸亏找到了gitee上的源,感谢gitee/githubplus作者

下载编译步骤如下:
编译grpc需要go支持,windows编译需要nasm,在ubuntu上可使用apt直接安装

sudo apt install golang yasm nasm

git clone https://gitee.com/githubplus/grpc.git
cd grpc
git tag
git checkout v1.20.0

修改.gitmodules文件,替换其中的github源为gitee源

[submodule "third_party/zlib"]path = third_party/zliburl = https://gitee.com/githubplus/zlib# When using CMake to build, the zlib submodule ends up with a# generated file that makes Git consider the submodule dirty. This# state can be ignored for day-to-day development on gRPC.ignore = dirty
[submodule "third_party/protobuf"]path = third_party/protobufurl = https://gitee.com/githubplus/protobuf.gitbranch = 3.0.x
[submodule "third_party/gflags"]path = third_party/gflagsurl = https://gitee.com/githubplus/gflags.git
[submodule "third_party/googletest"]path = third_party/googletesturl = https://gitee.com/githubplus/googletest.git
[submodule "third_party/boringssl"]path = third_party/boringsslurl = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/benchmark"]path = third_party/benchmarkurl = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/boringssl-with-bazel"]path = third_party/boringssl-with-bazelurl = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/cares/cares"]path = third_party/cares/caresurl = https://gitee.com/githubplus/c-ares.gitbranch = cares-1_12_0
[submodule "third_party/bloaty"]path = third_party/bloatyurl = https://gitee.com/githubplus/bloaty.git
[submodule "third_party/abseil-cpp"]path = third_party/abseil-cppurl = https://gitee.com/githubplus/abseil-cpp
[submodule "third_party/libcxxabi"]path = third_party/libcxxabiurl = https://gitee.com/githubplus/libcxxabi.gitbranch = release_60
[submodule "third_party/libcxx"]path = third_party/libcxxurl = https://gitee.com/githubplus/libcxx.gitbranch = release_60
[submodule "third_party/data-plane-api"]path = third_party/data-plane-apiurl = https://gitee.com/githubplus/data-plane-api.git
[submodule "third_party/googleapis"]path = third_party/googleapisurl = https://gitee.com/githubplus/googleapis.git
[submodule "third_party/protoc-gen-validate"]path = third_party/protoc-gen-validateurl = https://gitee.com/githubplus/protoc-gen-validate.git
[submodule "third_party/upb"]path = third_party/upburl = https://gitee.com/githubplus/upb.git

git submodule update --init

cd third_party/protobuf

类似修改protobuf.gitmodules后,执行git submodule update --init

[submodule "third_party/benchmark"]path = third_party/benchmarkurl = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/googletest"]path = third_party/googletesturl = https://gitee.com/githubplus/googletest.gitignore = dirty

使用cmake构建

mkdir build/linux-x86_64
cd build/linux-x864_64
cmake ../..
make

使用mingw交叉编译

mkdir -p build/mingw32
cd build/mingw32
cmake ../.. -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86
make grpc++

mkdir -p build/mingw64
cd build/mingw64
cmake ../.. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64
make grpc++

error

Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)

include/grpc/impl/codegen/port_platform.h中添加

#if !defined(_WIN32_WINNT) || _WIN32_WINNT <0x0600
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif#ifndef _WIN32_WINNT
#error \ "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
#else /* !defined(_WIN32_WINNT) */
#if (_WIN32_WINNT <0x0600)
#error \ "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
#endif /* _WIN32_WINNT <0x0600 */
#endif /* defined(_WIN32_WINNT) */

find . -name *.a静态库

./libgrpc.a
./libgrpc&#43;&#43;.a
./libaddress_sorting.a
./libgpr.a
./third_party/protobuf/libprotobuf.a
./third_party/boringssl/ssl/libssl.a
./third_party/boringssl/crypto/libcrypto.a
./third_party/cares/cares/lib/libcares.a
./third_party/zlib/libzlibstatic.a

Makefile中链接

GRPC_LIBS &#43;&#61; protobuf grpc&#43;&#43; grpc gpr address_sorting cares ssl crypto z
LDFLAGS &#43;&#61; $(addprefix -l, $(GRPC_LIBS))

ubuntu16.04下编译好的库https://gitee.com/ithewei/grpc-release.git


推荐阅读
author-avatar
手机用户2702933671_440
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有