Ubuntu22.04 交叉编译gcc9.5 for arm

一、准备

环境:ubuntu22.04为刚刚安装,未安装gcc等包

vi ~/.bashrc输入

export PATH=$PATH:/opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin

保存,reboot

安装:

sudo apt install cmake
sudo apt install gawk
sudo apt install bison

第一步:安装glibc-2.34

mkdir build
cd build

../configure --prefix=${PWD}/install \
--build=arm-linux-gnu \
--host=arm-linux-gnu \
--target=arm-linux-gnu \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-gnueabihf-g++ \
CPP=arm-linux-gnueabihf-cpp \
--disable-multilib libc_cv_forced_unwind=yes

make
make install

第二步:编译gmp-6.1.0

./configure --prefix=${PWD}/install/ --host=arm-linux --disable-assembly CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++

make 
make install

第三步:编译mpfr-3.1.4

./configure --prefix=${PWD}/install --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-gmp=/opt/gmp-6.1.0/install

make
make install

第四步:编译mpc-1.03

./configure --prefix=${PWD}/install --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-gmp=/opt/gmp-6.1.0/install --with-mpfr=/opt/mpfr-3.1.4/install

make
make install

第五步:编译isl-0.18

将/opt/gmp-6.1.0/install/lib目录下所有库文件拷贝到gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/,

然后执行

./configure --prefix=${PWD}/install --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-gmp-prefix=/opt/gmp-6.1.0/install

make
make install

第六步:编译gcc-9.5

删除cc

cd /usr/bin
sudo rm cc
sudo ln -s /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc cc
reboot

然后安装一些库,要不然编译不过

sudo apt-get install lsb-core lib32stdc++6

然后执行

./configure --prefix=${PWD}/build \
--with-gmp=/opt/gmp-6.1.0/install \
--with-mpfr=/opt/mpfr-3.1.4/install \
--with-mpc=/opt/mpc-1.0.3/install \
--with-isl=/opt/isl-0.18/install \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-gnueabihf-g++ \
CPP=arm-linux-gnueabihf-cpp \
--host=arm-linux-gnueabihf \
--target=arm-linux-gnueabihf \
--with-newlib \
--without-headers \
--enable-initfini-array \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-decimal-float \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libstdcxx \
--enable-checking=release \
--enable-languages=c,c++

make -j8 all-gcc
make install-gcc

编译结果

编译gmp遇到问题:

问题:Oops, mp_limb_t is 64 bits, but the assembler code

解决:https://gist.github.com/cwoac/5844398

I realised the first failure was because it tried to build the 64 bit code on a 32 bit platform.

The attached gist is the failure when running with --32-bit.

This can be worked around by adding --disable-assembly to the configure call

同时:

sudo apt-get install m4

备注:

gcc-9.5源码根目录/contrib/download_prerequisites 里面地有需要依赖的库源码版本,可以直接执行./contrib/download_prerequisites下载

相关推荐
算法与编程之美26 分钟前
文件的写入与读取
linux·运维·服务器
xianwu54343 分钟前
反向代理模块
linux·开发语言·网络·git
Amelio_Ming1 小时前
Permissions 0755 for ‘/etc/ssh/ssh_host_rsa_key‘ are too open.问题解决
linux·运维·ssh
Ven%2 小时前
centos查看硬盘资源使用情况命令大全
linux·运维·centos
TeYiToKu3 小时前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm
dsywws3 小时前
Linux学习笔记之时间日期和查找和解压缩指令
linux·笔记·学习
yeyuningzi3 小时前
Debian 12环境里部署nginx步骤记录
linux·运维·服务器
上辈子杀猪这辈子学IT3 小时前
【Zookeeper集群搭建】安装zookeeper、zookeeper集群配置、zookeeper启动与关闭、zookeeper的shell命令操作
linux·hadoop·zookeeper·centos·debian
minihuabei3 小时前
linux centos 安装redis
linux·redis·centos
lldhsds4 小时前
书生大模型实战营第四期-入门岛-1. Linux前置基础
linux