一、安装Ubuntu22.04
sudo apt install vim net-tools openssh-server
二、安装必要项
sudo apt update
sudo apt upgrade
sudo apt install build-essential gawk git texinfo bison flex
三、下载必备软件包
1.glibc
https://ftp.gnu.org/gnu/glibc/glibc-2.38.tar.gz
2.gcc
https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
3.binutils
https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz
4.Linux kernel
https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.6.tar.gz
下载完成后存在在/opt目录下
四、在/opt目录下创建编译文件夹,且解压文件
mkdir build-gcc
mkdir build-glibc
mkdir build-utils
mkdir packet #gcc 打包目录
五、下载gcc依赖包
cd /opt/gcc-13.2.0/
./contrib/download_prerequisites
这里主要下载的是gmp、mpfr、mpc、isl等库
六、安装内核头文件
cd /opt/linux-6.6
make ARCH=arm INSTALL_HDR_PATH=/opt/packet/arm-linux-gnueabihf headers_install
rv1126 是32位的板子,故ARCH=arm,如需要64位的板子则:
make ARCH=arm64 INSTALL_HDR_PATH=/opt/packet/arm-linux-gnueabihf headers_install
七、编译binutils
cd /opt/build-utils
../binutils-2.41/configure --prefix=/opt/packet --target=arm-linux-gnueabihf --with-arch=armv7l --with-fpu=vfp --with-float=hard --disable-multilib
make
make install
rv1126的板子是armv7l, 故 --with-arch=armv7l
八、部分编译gcc
cd /opt/build-gcc
#../gcc-13.2.0/configure --prefix=/opt/packet --target=arm-linux-gnueabihf --enable-languages=c,c++,fortran --with-fpu=vfp --with-float=hard --disable-multilib../gcc-13.2.0/configure --prefix=/opt/packet --target=arm-linux-gnueabihf --enable-languages=c,c++ --with-fpu=vfp --with-float=hard --disable-multilib --enable-libstdcxx --enable-libgm2 --enable-libssp --enable-sharedmake -j8 all-gcc
make install-gcc
九、部分编译glibc
cd /opt/build-glibcexport PATH=$PATH:/opt/packet/bin../glibc-2.38/configure \--prefix=/opt/packet/arm-linux-gnueabihf \--build=$MACHTYPE \--host=arm-linux-gnueabihf \--target=arm-linux-gnueabihf \--with-arch=armv7l \--with-fpu=vfp \--with-float=hard \--with-headers=/opt/packet/arm-linux-gnueabihf/include \--disable-multilib \libc_cv_forced_unwind=yesmake install-bootstrap-headers=yes install-headers make -j8 csu/subdir_libinstall csu/crt1.o csu/crti.o csu/crtn.o /opt/packet/arm-linux-gnueabihf/libarm-linux-gnueabihf-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/packet/arm-linux-gnueabihf/lib/libc.sotouch /opt/packet/arm-linux-gnueabihf/include/gnu/stubs.h
十、接着部分编译gcc
cd /opt/build-gcc
make -j8 all-target-libgcc
make install-target-libgcc
十一、全编译glibc
cd /opt/build-glibcexport PATH=$PATH:/opt/packet/binmake -j8make install
十二、全编译gcc
cd /opt/build-gcc
make -j8 all-target-libgcc
make install-target-libgcc#编译libstdc++.so.6
make -j8 all-target-libstdc++-v3
make install-target-libstdc++-v3
查看文件
十三、测试
1.创建build.sh
#!/bin/bash/opt/packet/bin/arm-linux-gnueabihf-gcc --static test.c -o ./test
2.创建test.c
#include <stdio.h>int main(int argc, const char *argv[])
{printf("Hello World\n");return 0;
}
3.执行
sudo chmod 777 ./build.sh
./build.sh
4.将test这个执行程序拷贝到arm板
十四、参考链接
aarch64-linux-gnu_交叉编译工具链_gcc-9.3.0-x86_64_arrch64-linux-gnu-CSDN博客
创建飞腾CPU的交叉编译环境_飞腾内核编译-CSDN博客
交叉编译生成可以在ARM64平台上运行的gcc_gdb arm64交叉编译-CSDN博客