【分享】使用Xilinx PetaLinux ARM64 SDK,交叉编译第三方软件

2022-03-23 10:13:27 浏览数 (1)

介绍

以前为ARM64编译软件包,直接在Makefile里指定交叉编译器、sysroot的路径,就能成功编译。

问题

最近编译一个使用CMake的软件包,按照使用 cmake 进行交叉编译 的说明,在CMakeLists.txt添加下面的内容后,仍然不能成功编译。

代码语言:javascript复制
set(CMAKE_SYSTEM_NAME Linux)​
set(TOOLCHAIN_PATH /opt/Xilinx/peta/2021.2/gcc-arm-linux-gnueabi)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-xilinx-linux-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-xilinx-linux-g  )

解决办法

经过尝试,发现安装PetaLinux/YOCTO生成的ARM64 SDK,再导入其中的环境变量,按通常的流程执行cmake和make,就能成功编译。

详细记录

获取SDK

可以使用命令"petalinux-build --sdk"编译SDK。编译成功后,sdk.sh在image/linux目录下。也可以直接从Common Images for Embedded Platforms 下载对应器件、版本的Common Images,解压后得到sdk.sh。再安装sdk.sh,能得到相关的编译工具和软件包文件。

导入ARM64 SDK的环境变量:

代码语言:javascript复制
$ source /opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/environment-setup-cortexa72-cortexa53-xilinx-linux 

检查系统变量

系统里会增加相关的变量。比如最最重要的编译器的变量:

代码语言:javascript复制
$ env | grep CXX
CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
OE_QMAKE_CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 

CC/CPP/CXX/LD的变量里,均会增加sysroot的路径,以及相关选项。

代码语言:javascript复制
KCFLAGS=--sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CC=aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_CC=aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_LINK=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CPP=aarch64-xilinx-linux-gcc -E  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
LD=aarch64-xilinx-linux-ld  --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux

可以检测编译器等工具的路径和版本:

代码语言:javascript复制
$ which $CC
/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-gcc

$CC -v
Using built-in specs.
COLLECT_GCC=aarch64-xilinx-linux-gcc
COLLECT_LTO_WRAPPER=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/10.2.0/lto-wrapper
Target: aarch64-xilinx-linux
Configured with: ../../../../../../work-shared/gcc-10.2.0-r0/gcc-10.2.0/configure --build=x86_64-linux --host=x86_64-petalinux-linux --target=aarch64-xilinx-linux --prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr --exec_prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr --bindir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux --sbindir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux --libexecdir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux --datadir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share --sysconfdir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/etc --sharedstatedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/com --localstatedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/var --libdir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib/aarch64-xilinx-linux --includedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include --oldincludedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include --infodir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share/info --mandir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/scratch/jenkins-BUILDS-eSDK-2021.2_stable-pipeline-build-89_VersalFullPrime/build/tmp/work/x86_64-nativesdk-petalinux-linux/gcc-cross-canadian-aarch64/10.2.0-r0/recipe-sysroot --with-gnu-ld --enable-shared --enable-languages=c,c   --enable-threads=posix --enable-multilib --enable-default-pie --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=aarch64-xilinx-linux- --without-local-prefix --disable-install-libiberty --enable-lto --disable-libssp --enable-libitm --disable-bootstrap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c  /10.2.0 --with-build-time-tools=/scratch/jenkins-BUILDS-eSDK-2021.2_stable-pipeline-build-89_VersalFullPrime/build/tmp/work/x86_64-nativesdk-petalinux-linux/gcc-cross-canadian-aarch64/10.2.0-r0/recipe-sysroot-native/usr/aarch64-xilinx-linux/bin --with-sysroot=/not/exist --with-build-sysroot=/scratch/jenkins-BUILDS-eSDK-2021.2_stable-pipeline-build-89_VersalFullPrime/build/tmp/work/x86_64-nativesdk-petalinux-linux/gcc-cross-canadian-aarch64/10.2.0-r0/recipe-sysroot --enable-poison-system-directories --disable-static --enable-nls --with-glibc-version=2.28 --enable-initfini-array --enable-__cxa_atexit
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC) 

$ which $CXX
/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-g  

$ which $LD
/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-ld

$LD -v
GNU ld (GNU Binutils) 2.35.1

可以检测cmake的路径和版本:

代码语言:javascript复制
$ which cmake
/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/cmake

$ cmake --version
cmake version 3.18.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).

增加的所有变量

增加的所有变量如下:

代码语言:javascript复制
OE_QMAKE_QDBUSCPP2XML=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/qdbuscpp2xml
ARCH=arm64
OE_QMAKE_INCDIR_QT=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/include
GDB=aarch64-xilinx-linux-gdb
OPENSSL_CONF=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/lib/ssl-1.1/openssl.cnf
CONFIG_SITE=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/site-config-cortexa72-cortexa53-xilinx-linux
OE_QMAKE_RCC=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/rcc
QT_CONF_PATH=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/qt.conf
SDKTARGETSYSROOT=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
M4=m4
OE_QMAKE_AR=aarch64-xilinx-linux-ar
KCFLAGS=--sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OECORE_ACLOCAL_OPTS=-I /opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/share/aclocal
CC=aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
READELF=aarch64-xilinx-linux-readelf
OECORE_DISTRO_VERSION=2021.2
OECORE_SDK_VERSION=2021.2
PKG_CONFIG_SYSROOT_DIR=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
OE_QMAKE_UIC=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/uic
STRIP=aarch64-xilinx-linux-strip
OBJCOPY=aarch64-xilinx-linux-objcopy
OE_QMAKE_PATH_HOST_BINS=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin
CONFIGURE_FLAGS=--target=aarch64-xilinx-linux --host=aarch64-xilinx-linux --build=x86_64-linux --with-libtool-sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_QT_CONFIG=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/lib/mkspecs/qconfig.pri
OECORE_NATIVE_SYSROOT=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux
RANLIB=aarch64-xilinx-linux-ranlib
OBJDUMP=aarch64-xilinx-linux-objdump
AS=aarch64-xilinx-linux-as 
AR=aarch64-xilinx-linux-ar
OE_QMAKE_QDBUSXML2CPP=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/qdbusxml2cpp
TARGET_PREFIX=aarch64-xilinx-linux-
OE_QMAKE_CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_STRIP=aarch64-xilinx-linux-strip
OE_QMAKE_CC=aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OE_QMAKE_MOC=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/bin/moc
OE_QMAKE_CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
OE_QMAKE_LIBDIR_QT=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/lib
NM=aarch64-xilinx-linux-nm
OE_QMAKE_LINK=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CXX=aarch64-xilinx-linux-g    -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
OECORE_TARGET_OS=linux
OE_QMAKE_CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
QMAKESPEC=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/lib/mkspecs/linux-oe-g  
OECORE_TARGET_ARCH=aarch64
OECORE_TARGET_SYSROOT=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
CROSS_COMPILE=aarch64-xilinx-linux-
OE_QMAKE_LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now
OE_CMAKE_TOOLCHAIN_FILE=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/x86_64-petalinux-linux/usr/share/cmake/OEToolchainConfig.cmake
CPPFLAGS=
LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=
OECORE_BASELIB=lib
PKG_CONFIG_PATH=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/lib/pkgconfig:/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux/usr/share/pkgconfig
CPP=aarch64-xilinx-linux-gcc -E  -mcpu=cortex-a72.cortex-a53 -march=armv8-a crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux
LD=aarch64-xilinx-linux-ld  --sysroot=/opt/Xilinx/peta/2021.2/vck190_sdk_0121_1802/sysroots/cortexa72-cortexa53-xilinx-linux

0 人点赞