• Ubuntu22.04 交叉编译GCC13.2.0 for Rv1126


    一、安装Ubuntu22.04 

    sudo apt install vim net-tools openssh-server

    二、安装必要项

    1. sudo apt update
    2. sudo apt upgrade
    3. 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目录下创建编译文件夹,且解压文件

    1. mkdir build-gcc
    2. mkdir build-glibc
    3. mkdir build-utils
    4. mkdir packet #gcc 打包目录

     

    五、下载gcc依赖包

    1. cd /opt/gcc-13.2.0/
    2. ./contrib/download_prerequisites

    这里主要下载的是gmp、mpfr、mpc、isl等库

    六、安装内核头文件

    1. cd /opt/linux-6.6
    2. 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

    1. cd /opt/build-utils
    2. ../binutils-2.41/configure --prefix=/opt/packet --target=arm-linux-gnueabihf --with-arch=armv7l --with-fpu=vfp --with-float=hard --disable-multilib
    3. make
    4. make install

    rv1126的板子是armv7l, 故 --with-arch=armv7l

     

    八、部分编译gcc

    1. cd /opt/build-gcc
    2. #../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
    3. ../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-shared
    4. make -j8 all-gcc
    5. make install-gcc

    九、部分编译glibc

    1. cd /opt/build-glibc
    2. export PATH=$PATH:/opt/packet/bin
    3. ../glibc-2.38/configure \
    4. --prefix=/opt/packet/arm-linux-gnueabihf \
    5. --build=$MACHTYPE \
    6. --host=arm-linux-gnueabihf \
    7. --target=arm-linux-gnueabihf \
    8. --with-arch=armv7l \
    9. --with-fpu=vfp \
    10. --with-float=hard \
    11. --with-headers=/opt/packet/arm-linux-gnueabihf/include \
    12. --disable-multilib \
    13. libc_cv_forced_unwind=yes
    14. make install-bootstrap-headers=yes install-headers
    15. make -j8 csu/subdir_lib
    16. install csu/crt1.o csu/crti.o csu/crtn.o /opt/packet/arm-linux-gnueabihf/lib
    17. arm-linux-gnueabihf-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/packet/arm-linux-gnueabihf/lib/libc.so
    18. touch /opt/packet/arm-linux-gnueabihf/include/gnu/stubs.h

     

    十、接着部分编译gcc

    1. cd /opt/build-gcc
    2. make -j8 all-target-libgcc
    3. make install-target-libgcc

     

    十一、全编译glibc 

    1. cd /opt/build-glibc
    2. export PATH=$PATH:/opt/packet/bin
    3. make -j8
    4. make install

    十二、全编译gcc

    1. cd /opt/build-gcc
    2. make -j8 all-target-libgcc
    3. make install-target-libgcc

    查看文件

    十三、测试

    1.创建build.sh

    1. #!/bin/bash
    2. /opt/packet/bin/arm-linux-gnueabihf-g++ test.cpp -o ./test -lpthread

     2.创建test.cpp

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. using namespace std;
    8. std::mutex g_mutex;
    9. std::vector<int>g_vData;
    10. void process()
    11. {
    12. int n = 0;
    13. while(true){
    14. g_mutex.lock();
    15. g_vData.push_back(n++);
    16. g_mutex.unlock();
    17. }
    18. }
    19. void Process1()
    20. {
    21. while(true){
    22. g_mutex.lock();
    23. if(g_vData.size() > 0){
    24. std::vector<int>::iterator iter = g_vData.begin();
    25. printf("%d\n", *iter);
    26. g_vData.erase(iter);
    27. }
    28. g_mutex.unlock();
    29. }
    30. }
    31. int main()
    32. {
    33. printf("hello\n");
    34. std::thread* pthread = new std::thread(process);
    35. std::thread* pthread1 = new std::thread(Process1);
    36. sleep(-1);
    37. return 0;
    38. }

    3.执行

    1. sudo chmod 777 ./build.sh
    2. ./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博客

  • 相关阅读:
    进程与进程调度的基本过程
    面试必考精华版Leetcode437. 路径总和 III
    面向6G的编码调制和波形技术
    Flask学习(二):flask模板渲染
    MySQL8.0修改mysql允许远程连接
    4- 24
    layui 使用xm-select实现下拉框多选
    技术分享 跨越语言的艺术:Flask Session 伪造
    Python爬虫:安全与会话管理
    pytorch代码实现之空间通道重组卷积SCConv
  • 原文地址:https://blog.csdn.net/sz76211822/article/details/134531433