grpc gitee镜像编译

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

下载编译步骤如下:

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/zlib
	url = 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/protobuf
	url = https://gitee.com/githubplus/protobuf.git
	branch = 3.0.x
[submodule "third_party/gflags"]
	path = third_party/gflags
	url = https://gitee.com/githubplus/gflags.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/githubplus/googletest.git
[submodule "third_party/boringssl"]
	path = third_party/boringssl
	url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/benchmark"]
	path = third_party/benchmark
	url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/boringssl-with-bazel"]
	path = third_party/boringssl-with-bazel
	url = https://gitee.com/githubplus/boringssl.git
[submodule "third_party/cares/cares"]
	path = third_party/cares/cares
	url = https://gitee.com/githubplus/c-ares.git
	branch = cares-1_12_0
[submodule "third_party/bloaty"]
	path = third_party/bloaty
	url = https://gitee.com/githubplus/bloaty.git
[submodule "third_party/abseil-cpp"]
	path = third_party/abseil-cpp
	url = https://gitee.com/githubplus/abseil-cpp
[submodule "third_party/libcxxabi"]
	path = third_party/libcxxabi
	url = https://gitee.com/githubplus/libcxxabi.git
	branch = release_60
[submodule "third_party/libcxx"]
	path = third_party/libcxx
	url = https://gitee.com/githubplus/libcxx.git
	branch = release_60
[submodule "third_party/data-plane-api"]
	path = third_party/data-plane-api
	url = https://gitee.com/githubplus/data-plane-api.git
[submodule "third_party/googleapis"]
	path = third_party/googleapis
	url = https://gitee.com/githubplus/googleapis.git
[submodule "third_party/protoc-gen-validate"]
	path = third_party/protoc-gen-validate
	url = https://gitee.com/githubplus/protoc-gen-validate.git
[submodule "third_party/upb"]
	path = third_party/upb
	url = 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/benchmark
	url = https://gitee.com/githubplus/benchmark.git
[submodule "third_party/googletest"]
	path = third_party/googletest
	url = https://gitee.com/githubplus/googletest.git
	ignore = 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中添加

#undef  _WIN32_WINNT
#define _WIN32_WINNT 0x0600

#ifndef _WIN32_WINNT
 #error \
     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"

find . -name *.a静态库

./libgrpc.a
./libgrpc++.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 += protobuf grpc++ grpc gpr address_sorting cares ssl crypto z
LDFLAGS += $(addprefix -l, $(GRPC_LIBS))
发布了127 篇原创文章 · 获赞 135 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/GG_SiMiDa/article/details/103602666
今日推荐