Cross compile gRPC for ARM
This post will tell you how to cross compile gPRC static lib for ARM.
前段时间尝试交叉编译gRPC遇到了不少的麻烦,写篇post记录一下。
gRPC
Preparation
First of all, you should have gRPC source code. git clone it from github. Then update submodules:
1 | cd grpc |
Install zlib for your arm compiler[Optional]
libz is one of gRPC dependencies. If you haven’t installed it for your arm compiler yet, you may need to install it. You can get zlib at zlib Home Site. After download and unzip it, set cross compiler and build it:
1 | export CC=arm-linux-gnueabihf-gcc |
then install it if build succeed:
1 | make install prefix=/usr/arm-linux-gnueabihf |
Compile and install protobuf & gRPC for HOST
protobuf:
1 | cd grpc/third_party/protobuf |
gRPC:
1 | cd .. |
Cross compile static lib for ARM
make plugins first:
1 | make clean |
Cross compile gRPC:
1 | export GRPC_CROSS_COMPILE=true |
static is important. I tried to build shared lib but there will be a lot of errors because arm-linux-gnueabihf-ld doesn’t take “-Wl” as a parameter. If build succeed, you can find your static lib at “grpc/libs/opt”.
reference: https://github.com/grpc/grpc/issues/9719