To compile gocore You need a gccgo cross-compiler
-
build a target i386/i686 gcc cross-compiler with go enabled, follow the article http://wiki.osdev.org/GCC_Cross-Compiler
-
install nasm from your repositories
-
install qemu for test
-
compile:
make GCC=i686-elf-gcc GCCGO=i686-elf-gccgo
, replaceGCC
andGCCGO
with your binary name -
run on qemu:
make run-qemu QEMU=qemu-system-i386
, replaceQEMU
with your target binary name
交叉编译
https://wiki.osdev.org/GCC_Cross-Compiler https://wiki.osdev.org/Go_Bare_Bones
我用的binutils-2.34
和gcc-7.5.0
,按照教程走就可以了,除了gcc configure
这一步改成
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++,go --without-headers
源码安装高版本gcc如9.3.0时,可能会发生错误: gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+ 解决方法: 在gcc源码目录下, ./contrib/download_prerequisites, 会自动下载相关依赖.