码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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博客

  • 相关阅读:
    JavaScript 中的 apply、call、bind
    金九银十BAT互联网企业涨薪必备知识点:Jvm性能调优实战
    聊一聊如何截获 C# 程序产生的日志
    关于HTTP协议的概述
    Android技术分享|【Android踩坑】怀疑人生,主线程修改UI也会崩溃?
    Qt实现开机自启两种方法包含注意事项以及常见问题解决
    我所理解的 UI Toolkit 启蒙阶段(一)
    通义灵码,阿里巴巴的编程辅助工具
    掌握这些 Spring Boot 启动扩展点,已经超过 90% 的人了!
    Mysql 中遇到的坑
  • 原文地址:https://blog.csdn.net/sz76211822/article/details/134531433
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号