- 重点要参考官方文档:https://github.com/grpc/grpc/blob/master/test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh
- 如果要支持AG35或AG55X,要修改camke config.
- 按官方文档可能还需要安装libssl-dev.
- 此次编译源码选的grpc-v1.45.2,官网下载,或gitbub下载都可以.
1.cmake版本至少3.5.1
#官方用的3.16
#Install CMake 3.16
apt-get update && apt-get install -y wget
wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-Linux-x86_64.sh
sh cmake-linux.sh -- --skip-license --prefix=/usr
rm cmake-linux.sh
2.编译gRPC相关工具
cd grpc-v1.45.2
mkdir -p cmake/build
cd cmake/build
cmake -DCMAKE_BUILD_TYPE=Release -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_SSL_PROVIDER=package ../..
make install
3.建立cmake config
#重点来了,需要修改硬件对应的编译工具链
vim /tmp/toolchain.cmake
# Write a toolchain file to use for cross-compiling.
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR armhf)
set(CMAKE_STAGING_PREFIX /tmp/stage)
# 以下两行根据所用的交叉编译器所在路径修改
set(QL_TOOLCHAIN_PATH /opt/ql_crosstools/ql-ag35-le22-gcc640-v1-toolchain/gcc/usr/bin/arm-oe-linux-gnueabi)
set(CMAKE_C_COMPILER ${QL_TOOLCHAIN_PATH}/arm-oe-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${QL_TOOLCHAIN_PATH}/arm-oe-linux-gnueabi-g++)
add_compile_options("-marm")
add_compile_options("-march=armv7-a")
add_compile_options("-mfpu=neon")
add_compile_options("-mfloat-abi=hard")
#这个应该不是必须的,这是之前编译app用的
set(AG35_SDK_DIR /home/vico/work/sdk/ql-ol-extsdk-ag35_ocpu)
SET(ENV{LDFLAGS} "$ENV{LDFLAGS} -marm -march=armv7-a -mfpu=neon -mfloat-abi=hard -s -no-pie")
set(CMAKE_SYSROOT /home/vico/work/sdk/ql-ol-extsdk-ag35_ocpu/ql-sysroots)
4.交叉编译gRPC
cd grpc-v1.45.2
mkdir -p cmake/build_arm
cd cmake/build_arm
cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install ../..
make install
5.交叉编译demo
cd grpc-v1.45.2/examples/cpp/helloworld
mkdir -p cmake/build_arm
cd cmake/build_arm
cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-Dabsl_DIR=/tmp/stage/lib/cmake/absl \
-DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \
-Dutf8_range_DIR=/tmp/stage/lib/cmake/utf8_range \
-DgRPC_DIR=/tmp/stage/lib/cmake/grpc \
../..
make
标签:tmp,set,cmake,交叉,gRPC,编译,DCMAKE,grpc From: https://www.cnblogs.com/edenpei/p/17340321.html