安装 g+±aarch64-linux-gnu 交叉编译器

$sudo apt install g++-aarch64-linux-gnu #安装
#如果安装失败,则切换下载服务器到(中国-mirrors.aliyun.com)
#再执行 sudo apt update
#如果提示E:无法修正的错误
#卸载 sudo apt-get autoremove binutils-common
#然后执行sudo apt install g++-aarch64-linux-gnu

$aarch64-linux-gnu-g++ -v  #查看默认安装的gcc版本
$sudo apt install cmake-gui  #安装 cmake-gui 有些需要选择性编译的库使用较方便

编译如果不成功, 把源码删除,终端重新打开,重新编译。
如果源码不支持cmake, 则可以使用下面方式
在源码中打开终端输入一下命令行

$export CC=/usr/bin/aarch64-linux-gnu-gcc
$export CXX=/usr/bin/aarch64-linux-gnu-g++
$make aarch64-linux    #如果报错则换成 arm-linux, 如果再报错则直接: $make
$sudo make install  # 默认安装到/usr/local/lib

如果源码支持cmake, 则可以使用下面脚本
打开 cmake-gui, 添加源码及编译输出目录后自动弹出, 选择第三个toolChain,选择下面的文件即可。
linuxToolChain.cmake

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

# set compiler
# C Compiler
# apt-get install gcc-arm-linux-gnueabi
# apt-get install g++-arm-linux-gnueabihf
# CXX Compiler
# apt-get install gcc-arm-linux-gnueabi
# apt-get install g++-arm-linux-gnueabihf

# useless
# set(CMAKE_SYSROOT "")

# when install should use this
# set(CMAKE_STAGING_PREFIX "")

# we use gnueabihf, namely -mfloat-abi=hard
#set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
#set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)

#---------------------------------------------
#-DCMAKE_TOOLCHAIN_FILE=./toolChain.cmake

set(target_triple "aarch64-linux-gnu")
get_filename_component(currdir ${CMAKE_CURRENT_LIST_FILE} ABSOLUTE)
get_filename_component(currdir ${currdir} DIRECTORY)
set(clangpath /usr/bin/aarch64-linux-gnu-g++)
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBHEBI_CROSS_GCC_TOOLCHAIN_ARG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBHEBI_CROSS_GCC_TOOLCHAIN_ARG}")

#---------------------------------------------
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Logo

更多推荐