(一)交叉编译工具链安装
# 查看可以安装的版本
apt-cache search aarch64
# 选择可以安装的版本进行安装
# 此处选择gcc-5-aarch64-linux-gnu以及g++-5-aarch64-linux-gnu进行安装
sudo apt-get install gcc-5-aarch64-linux-gnu
sudo apt-get install gcc-5-aarch64-linux-gnu
# 安装依赖
sudo apt --fix-broken install
# 安装一个没有版本号的gcc和g++
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install gcc-aarch64-linux-gnu
# 查看版本
aarch64-linux-gnu-g++ -v
aarch64-linux-gnu-gcc -v
(二)查看安装路径
~$ whereis aarch64-linux-gnu-gcc
aarch64-linux-gnu-gcc: /usr/bin/aarch64-linux-gnu-gcc /usr/share/man/man1/aarch64-linux-gnu-gcc.1.gz
(三)CMake交叉编译
测试文件结构
.
├── bin
├── build
├── CMakeLists.txt
├── include
└── src
└── test.cpp
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set (CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set (CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")
project(main)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
include_directories (${PROJECT_SOURCE_DIR}/include)
aux_source_directory(src SRC_LIST)
add_executable(main ${SRC_LIST})
参考文章:
linux 交叉编译 C和C++_aarch64-linux-gnu-gcc查看版本_weixin_45302027的博客-CSDN博客
ubuntu16.04 安装交叉编译工具aarch64-linux-gnu-gccg++_ubuntu 安装aarch64-linux-gnu-gcc_普通网友的博客-CSDN博客