zynq7000交叉编译Boost和gRPC-(arm-linux-gnueabihf-gcc/g++)

首先,boost、gRPC如果采用官方网站或者github上下载zip问题非常大,因为缺少很多第三方依赖库。

解决办法:采用git下载,再git第三方库,下载网上不够就只能hehe,大家都懂的。如下:

git clone --recurse-submodules -b v1.55.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc 
 $ cd grpc
 $ git submodule update --init

boost下载也一样:https://github.com/boostorg/boost.git

下面就是编译:

grpc一定要安装官方的较差编译方法,grpc/BUILDING.md at master · grpc/grpc · GitHub

其实就是修改一下grpc/test/distrib/cpp/run_distrib_test_cmake_aarch64_cross.sh文件,改成我们字节编译器和输出路径。然后以管理员方式,执行一下这个文件就可以了搞定了。下面是我的编译文件:

#!/bin/bash
# Copyright 2017 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

cd "$(dirname "$0")/../../.."

# Install openssl (to use instead of boringssl)
apt-get update && apt-get install -y libssl-dev

# 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

# Use externally provided env to determine build parallelism, otherwise use default.
GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS=${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS:-4}

# Build and install gRPC for the host architecture.
# We do this because we need to be able to run protoc and grpc_cpp_plugin
# while cross-compiling.
mkdir -p "cmake/build"
pushd "cmake/build"
cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DgRPC_INSTALL=ON \
  -DgRPC_BUILD_TESTS=OFF \
  -DgRPC_SSL_PROVIDER=package \
  ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd


# Build helloworld example for x64.
# As above, it will find and use protoc and grpc_cpp_plugin
# for the host .
mkdir -p "examples/cpp/helloworld/cmake/build_x64"
pushd "examples/cpp/helloworld/cmake/build_x64"
cmake   -DCMAKE_BUILD_TYPE=Release   ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}"
popd


# Write a toolchain file to use for cross-compiling.
cat > /mnt/soft/local/cross_arm/grpc/toolchain.cmake <<'EOT'
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR aarch32)
set(CMAKE_STAGING_PREFIX /mnt/soft/local/cross_arm/grpc/stage)
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
EOT

# Build and install gRPC for ARM.
# This build will use the host architecture copies of protoc and
# grpc_cpp_plugin that we built earlier because we installed them
# to a location in our PATH (/usr/local/bin).
mkdir -p "cmake/build_arm"
pushd "cmake/build_arm"
cmake -DCMAKE_TOOLCHAIN_FILE=/mnt/soft/local/cross_arm/grpc/toolchain.cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=/mnt/soft/local/cross_arm/grpc/install \
      ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd

# Build helloworld example for ARM.
# As above, it will find and use protoc and grpc_cpp_plugin
# for the host architecture.
mkdir -p "examples/cpp/helloworld/cmake/build_arm"
pushd "examples/cpp/helloworld/cmake/build_arm"
cmake -DCMAKE_TOOLCHAIN_FILE=/mnt/soft/local/cross_arm/grpc/toolchain.cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -Dabsl_DIR=/mnt/soft/local/cross_arm/grpc/stage/lib/cmake/absl \
      -DProtobuf_DIR=/mnt/soft/local/cross_arm/grpc/stage/lib/cmake/protobuf \
      -DgRPC_DIR=/mnt/soft/local/cross_arm/grpc/stage/lib/cmake/grpc \
      ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}"
popd

总的来讲,grpc的依赖库管理的非常好,编译一次成功,不需要修改什么。

接下来讲一下boost编译:

首先,git下载库boost要实现完整编译,还缺少几个核心库:

 编译这些依赖库,安装到arm-linux-gnueabihf-gcc自己的目录下,否则编译找不到。

下面是我的编译文件:

# B2 Configuration
# Automatically generated by bootstrap.sh
##########################################################################################
# build :   ./b2 -layout=versioned variant=release cxxflags='-fPIC -std=c++17' runtime-link=static link=static threading=multi 
# build and install:  ./b2 -layout=versioned variant=release cxxflags='-fPIC -std=c++17' runtime-link=static link=static threading=multi install
##########################################################################################
import option ;
import feature ;

# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
using gcc : arm : arm-linux-gnueabihf-g++ -mtune=cortex-a9 -march=armv7-a -std=c++11 -fPIC -marm -mfpu=neon -mfloat-abi=hard -ffast-math --sysroot=/mnt/soft/local/cross_arm/sysroot_all  ; 
}

project : default-build <toolset>gcc ;

# Python configuration
import python ;
if ! [ python.configured ]
{
    using python : 3.6 : /usr :  /usr/arm-linux-gnueabihf/include/python3.6m :  /usr/arm-linux-gnueabihf/lib/python3.6 ;
}

path-constant ICU_PATH : /usr ;


# List of --with-<library> and --without-<library>
# options. If left empty, all libraries will be built.
# Options specified on the command line completely
# override this variable.
libraries =  ;

# These settings are equivalent to corresponding command-line
# options.
option.set prefix : /mnt/soft/local/boost_git/cross_arm ;
option.set exec-prefix : /mnt/soft/local/boost_git/cross_arm ;
option.set libdir : /mnt/soft/local/boost_git/cross_arm/lib ;
option.set includedir : /mnt/soft/local/boost_git/cross_arm/include ;

# Stop on first error
option.set keep-going : false ;

 然后执行B2就可与了哈。

 就这样吧,需要的同学可与点击下面连接:

(84条消息) xilinxzynq7000系列交叉编译后的Boost和gRPC资源-CSDN文库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值