Debian一个槽点是gcc/g++/gfortran-multilib和交叉编译工具链如gcc/g++/gfortran-riscv64-linux-gnu会互相卸载,解决办法如下:
1、安装build-essential(gcc/g++/libc6-dev/make/dpkg-dev)和gfortran,记下被安装的gcc版本,这里假设被安装的是gcc-12
bash
sudo apt install build-essential gfortran
2、multilib只安装dev库
事实上gcc/g++/gfortran-multilib和gcc/g++/gfortran-12-multilib等是只含有少量符号链接的空包,因此实际上不必安装这些包,只安装对应的dev库,并手动创建某些重要的符号链接即可
bash
# 防止libc6-i386/x32-dev试图安装gcc-multilib
# 也可以sudo nano /etc/apt/apt.conf.d/99synaptic然后手动编辑为false
sudo sed -i -e 's/APT::Install-Recommends "true";/APT::Install-Recommends "false";/g' /etc/apt/apt.conf.d/99synaptic
# 安装32位库
sudo apt install libc6-dev-i386 lib32gcc-12-dev lib32stdc++-12-dev lib32gfortran-12-dev
# 安装x32(64位指令集32位ABI)库
sudo apt install libc6-dev-x32 libx32gcc-12-dev libx32stdc++-12-dev libx32gfortran-12-dev
# gcc-multilib创建了这个链接
sudo ln -sv x86_64-linux-gnu/asm /usr/include/asm
x32程序如果需要运行的话,还需要sudo nano /etc/default/grub将相关内容改为下面的形式,然后sudo update grub
bash
GRUB_CMDLINE_LINUX_DEFAULT="quiet syscall.x32=y"
GRUB_CMDLINE_LINUX="syscall.x32=y"
3、安装其他交叉编译工具链
bash
sudo apt install g{cc,++,fortran}-riscv-linux-gnu