Debian 11 安装 RISC-V 和 Mips64 的 GNU gcc编译器工具链的笔记
RISC-V GNU Compiler Toolchain 的 github
这是 RISC-V C 和 C++ 交叉编译器。 它支持两种构建模式:通用的 ELF/Newlib 工具链和更复杂的 Linux-ELF/glibc 工具链。
gcc-toolchain-mips64 for the N64 的 github
此 repo 自动生成 MIPS64 工具链以允许对 N64 进行交叉编译。 二进制文件可以作为其他构建脚本的一部分下载,这可以节省设置开发人员环境的时间(至少 30 分钟),以便构建 N64 库,例如 libdragon。
分别访问这两个github
项目,下载编译完成的二进制工具包
- https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.03.14/riscv32-elf-ubuntu-22.04-nightly-2023.03.14-nightly.tar.gz
- https://github.com/n64-tools/gcc-toolchain-mips64/releases/download/11.3.0/gcc-toolchain-mips64-linux64.tar.gz
使用 xshell
的 rz
命令或者 winscp
传送到 Debian 11 的虚拟机系统。
mkdir -p /opt && cd /opt
tar xf riscv32-elf-ubuntu-22.04-nightly-2023.03.14-nightly.tar.gz
mkdir -p /opt/mips && cd /opt/mips
tar xf gcc-toolchain-mips64-linux64.tar.gz
# 测试工具的路径和环境是否完整
/opt/mips/bin/mips64-elf-gcc -v
/opt/riscv/bin/riscv32-unknown-elf-gcc -v
如果系统环境正常显示如下
root@debian:/opt# /opt/riscv/bin/riscv32-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/riscv/bin/riscv32-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/opt/riscv/libexec/gcc/riscv32-unknown-elf/12.2.0/lto-wrapper
Target: riscv32-unknown-elf
Configured with: /home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc/configure --target=riscv32-unknown-elf --prefix=/opt/riscv --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=g2ee5e430018 --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/riscv32-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc --disable-multilib --with-abi=ilp32d --with-arch=rv32gc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (g2ee5e430018)
root@debian:/opt# /opt/mips/bin/mips64-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/mips/bin/mips64-elf-gcc
COLLECT_LTO_WRAPPER=/opt/mips/bin/../libexec/gcc/mips64-elf/11.3.0/lto-wrapper
Target: mips64-elf
Configured with: ../gcc-source/configure --prefix=/home/runner/work/mips64-gcc-toolchain/mips64-gcc-toolchain/scripts/build/linux64 --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mips64-elf --with-arch=vr4300 --with-tune=vr4300 --enable-languages=c,c++ --without-headers --with-newlib --with-gnu-as=/home/runner/work/mips64-gcc-toolchain/mips64-gcc-toolchain/scripts/build/linux64/bin/mips64-elf-as --with-gnu-ld=/home/runner/work/mips64-gcc-toolchain/mips64-gcc-toolchain/scripts/build/linux64/bin/mips64-elf-ld --enable-checking=release --enable-shared --enable-shared-libgcc --disable-decimal-float --disable-gold --disable-libatomic --disable-libgomp --disable-libitm --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libssp --disable-libunwind-exceptions --disable-libvtv --disable-multilib --disable-nls --disable-rpath --disable-static --disable-threads --disable-win32-registry --enable-lto --enable-plugin --enable-static --without-included-gettext
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (GCC)
如果错误显示类似下面,缺少 GLIBC_2.32
库,需要升级 glibc
到 GLIBC_2.32
版本
mips64-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.32' not found (required by mips64-elf-gcc)
mips64-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.33' not found (required by mips64-elf-gcc)
mips64-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.34' not found (required by mips64-elf-gcc)
riscv/bin/riscv64-unknown-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.32' not found (required by riscv/bin/riscv64-unknown-elf-gcc)
riscv/bin/riscv64-unknown-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.33' not found (required by riscv/bin/riscv64-unknown-elf-gcc)
riscv/bin/riscv64-unknown-elf-gcc: /lib/x86_64-linux-gnu/libc.so.6: version "GLIBC_2.34' not found (required by riscv/bin/riscv64-unknown-elf-gcc)
Debian 11 上将 glibc
从版本 2.30 升级到 2.32 方法
-
编辑
sources.list
添加sid main
实验性软件源,再apt -t sid
安装软件包vim /etc/apt/sources.list # 国外选官方源 deb http://ftp.debian.org/debian sid main # 国内选中科大源 deb http://mirrors.ustc.edu.cn/debian/ sid main apt -t sid install libc6 libc6-dev libc6-dbg
设置环境变量和测试编译器
export PATH="$PATH:/opt/riscv/bin/" alias rvcc=riscv32-unknown-elf-gcc export PATH="$PATH:/opt/mips/bin/" alias mgcc=mips64-elf-gcc rvcc -v mgcc -v
- 建议将以上
export
命令 ,加入到~/.bashrc
文件末尾,每次进入容器能自动加载环境变量。
安装 QEMU
这个通用的开源机器和用户空间模拟器和虚拟器
apt install qemu qemu-user
gcc-toolchain-mips64
交叉编译问题待解决
# 错误已解决 mips64-elf/bin/as: error while loading shared libraries: libopcodes-2.38.so: cannot open shared object file: No such file or directory
echo "/opt/mips/x86_64-linux-gnu/mips64-elf/lib" > /etc/ld.so.conf.d/mips64-elf.conf
ldconfig
# 错误待解决 mips64-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400040
0 条评论