交叉编译gRPC

1. install zlib with /home/ibm/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --sysroot=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux

$./configure --prefix=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/usr --includedir=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/usr/include --libdir=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/lib/
$make 
$make install

2. intall openssl-1.1.1b

./Configure --prefix=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/usr --openssldir=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/usr/ssl --libdir=/home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/lib/  linux-armv4
$make 
$make install

3. cross compiling grpc
GRPC_CROSS_COMPILE=true
PROTOBUF_CONFIG_OPTS=--host=arm-linux --with-protoc=/usr/local/bin/protoc
HAS_PKG_CONFIG=false
#
# The steps for cross-compiling are as follows:
# First, clone and make install of grpc using the native compilers for the host.
# Also, install protoc (e.g., from a package like apt-get)
# Then clone a fresh grpc for the actual cross-compiled build
# Set the environment variable GRPC_CROSS_COMPILE to true
# Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
# Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
#  PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
# Set HAS_PKG_CONFIG=false
# To build tests, go to third_party/gflags and follow its ccmake instructions
# Make sure that you enable building shared libraries and set your prefix to
# something useful like /usr/local/cross
# You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
# additional required arguments for LD and AR (examples below)
# Then you can do a make from the cross-compiling fresh clone!
$make

$cp /home/ibm/arm-linux-gnueabihf/grpc/libs/opt/* /home/ibm/arm-linux-gnueabihf/sysroot-glibc-arm-linux/usr/lib/

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

修改grpc Makefile:

1、修改default 编译工具

DEFAULT_CC=/home/abc/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
DEFAULT_CXX=/home/abc/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++

2、设置protobuf 交叉编译变量:

GRPC_CROSS_COMPILE=true
PROTOBUF_CONFIG_OPTS=--host=arm-linux --with-protoc=/usr/local/bin/protoc
HAS_PKG_CONFIG=false

#
# The steps for cross-compiling are as follows:
# First, clone and make install of grpc using the native compilers for the host.
# Also, install protoc (e.g., from a package like apt-get)
# Then clone a fresh grpc for the actual cross-compiled build
# Set the environment variable GRPC_CROSS_COMPILE to true
# Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
# Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
#  PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
# Set HAS_PKG_CONFIG=false
# To build tests, go to third_party/gflags and follow its ccmake instructions
# Make sure that you enable building shared libraries and set your prefix to
# something useful like /usr/local/cross
# You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
# additional required arguments for LD and AR (examples below)
# Then you can do a make from the cross-compiling fresh clone!
#

 

3、执行make 时,设置host 端编译工具:

# The HOST compiler settings are used to compile the protoc plugins.
# In most cases, you won't have to change anything, but if you are
# cross-compiling, you can override these variables from GNU make's
# command line: make CC=cross-gcc HOST_CC=gcc

HOST_CC ?= $(CC)
HOST_CXX ?= $(CXX)
HOST_LD ?= $(LD)
HOST_LDXX ?= $(LDXX)

$make HOST_CXX=gcc  HOST_LD=/usr/bin/ld   HOST_LDXX=/usr/bin/ld
 

你可能感兴趣的:(交叉编译gRPC)