MacOS下配置aarch64交叉编译工具链
2024-08-06 本文已影响0人
望江樵夫
gcc v11.2.0-1
https://github.com/messense/homebrew-macos-cross-toolchains/releases
注意:所有的make install 安装出现权限错误,请检查交叉编译工具安装目录配置,千万不要加sudo,以免覆盖主机系统文件。
编译完成后安装路径被覆盖,可以从新执行一下cmake配置:
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
一、编译安装 glib2.81.1
https://gitlab.gnome.org/GNOME/glib/-/archive/2.81.1/glib-2.81.1.tar.gz
在glib根目录创建交叉编译脚本,并命名为:aarch64-arm-none-linux.txt
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
[properties]
c_args = []
c_link_args = []
[binaries]
c = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc'
cpp = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-g++'
ar = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc-ar'
ld = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc-ld'
objcopy = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-objcopy'
strip = '/opt/droidtools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-strip'
1、配置编译选项,打开终端,跳转到glib根目录,输入下面的命令
meson --prefix=/opt/droidtools/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu -Ddefault_library=both --cross-file aarch64-arm-none-linux.txt build_aarch64
2、编译命令:meson compile -C build_aarch64
3、安装命令:meson install -C build_aarch64
二、编译安装 LCM
git:/commit/f18f8a63ea670f1395a7422447b43859a01788ab
https://github.com/lcm-proj/lcm.git
在(/Users/mhming/Downloads/Deployment/,这个目录可自定义,注意cmake脚本路径即可)创建交叉编译工具配置脚本,并命名为:cross_aarch64.cmake
# cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
set(tools "/opt/droidtools/aarch64-unknown-linux-gnu/")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_BUILD_TYPE Release)
# set(CMAKE_STAGING_PREFIX /Users/mhming/Downloads/Deployment/compile_tools/stage)
set(CMAKE_INSTALL_PREFIX ${tools}/aarch64-unknown-linux-gnu/)
set(CMAKE_C_COMPILER ${tools}/bin/aarch64-unknown-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-unknown-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH ${tools}/aarch64-unknown-linux-gnu)
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)
set(_Python3_INCLUDE_DIR "/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/include/python3.12")
注:查找python头文件命令:python3-config --includes
1、终端进入LCM根目录,创建build_aarch64编译目录
mkdir build_aarch64
cd build_aarch64
2、配置选项加载
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
3、编译、安装
make & make install
lua、go、test等内容一般不需要可在CmakeList中注释掉,可减少环境配置内容。
三、编译安装yaml-cpp yaml-cpp-0.8.0
https://github.com/jbeder/yaml-cpp.git
1、终端进入yaml-cpp根目录,创建build_aarch64编译目录
mkdir build_aarch64
cd build_aarch64
2、配置选项加载
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
3、编译、安装
make & make install
四、编译安装 SOEM /commit/83c6264f9929991bcf2918514114d19efe308e2a
https://github.com/OpenEtherCATsociety/SOEM.git
1、终端进入SOEM根目录,创建build_aarch64编译目录
mkdir build_aarch64
cd build_aarch64
2、配置选项加载
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
3、编译、安装
make & make install
五、编译安装 Eigen 3.4.0
https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
解压后拷贝Eigen目录到:
/opt/droidtools/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/include
六、编译安装 grpc v1.65.4
https://github.com/grpc/grpc.git
1、终端进入gRPC根目录,创建build_aarch64编译目录
mkdir build_aarch64
cd build_aarch64
2、配置选项加载
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_USE_SYSTEMD=OFF ..
3、编译、安装
make & make install
七、安装
https://github.com/nlohmann/json.git
commit 960b763ecd144f156d05ec61f577b04107290137
1、终端进入json根目录,创建build_aarch64编译目录
mkdir build_aarch64
cd build_aarch64
2、配置选项加载
cmake -DCMAKE_TOOLCHAIN_FILE=/Users/mhming/Downloads/Deployment/compile_tools/cross_aarch64.cmake ..
3、编译、安装
make & make install