标签:return sub bootstra 编译 font win -- 报错 exp
Building GCC as a cross compiler for Raspberry Pi
How to Build a GCC Cross-Compiler
PC: ubuntu18.04 64位 (Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz)
GCC:gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
下面是我们交叉编译GCC用到的三个软件包:binutils,glibc以及gcc,下载链接如下:
binutils:https://mirrors.nju.edu.cn/gnu/binutils/,我下载的是binutils-2.32.tar.xz
glibc:https://ftp.gnu.org/gnu/glibc/,我下载的是glibc-2.30.tar.xz
gcc:https://github.com/gcc-mirror/gcc,我下载的是:gcc-9_2_0-release (切到tag标签,选择对应的tag)
sudo apt update sudo apt upgrade sudo apt install build-essential gawk git texinfo bison file
mkdir -p /home/pengdl/work/GNU/mk_cross_compiler/ cd /home/pengdl/work/GNU/mk_cross_compiler
$ pwd /home/pengdl/work/GNU/mk_cross_compiler $ mkdir code $ cd code $ tar -xf ./binutils-2.32.tar.xz- $ tar -xf ./glibc-2.30.tar.xz- $ tar -xf ./gcc-9_2_0-release.tar.gz
cd gcc-9_2_0/ ./contrib/download_prerequisites
cd /home/pengdl/work/GNU/mk_cross_compiler mkdir cross-gcc export PATH=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/bin:$PATH
cd /home/pengdl/aarch64/android_kernel/linux-4.14 make ARCH=arm64 INSTALL_HDR_PATH=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu headers_install
cd /home/pengdl/work/GNU/mk_cross_compiler mkdir build-binutils cd build-binutils/ ../code/binutils-2.32/configure --prefix=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc --target=aarch64-linux-gnu --disable-multilib --with-arch=armv8 make -j8 make install
下面开始编译glibc和gcc,由于这两个相互依赖,所以我们先部分编译gcc,然后部分编译glibc,最后全部编译gcc和glibc。
cd /home/pengdl/work/GNU/mk_cross_compiler mkdir build-gcc cd build-gcc ../code/gcc-9_2_0/configure --prefix=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc --target=aarch64-linux-gnu --enable-languages=c,c++ --disable-multilib make all-gcc -j8 make install-gcc
cd /home/pengdl/work/GNU/mk_cross_compiler mkdir build-glibc cd build-glibc/ ../code/glibc-2.30/configure --prefix=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu --build=$MACHINE --host=aarch64-linux-gnu --target=aarch64-linux-gnu --with-headers=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu/include --disable-multilib libc_cv_forced_unwind=yes make install-bootstrap-headers=yes install-headers make -j8 csu/subdir_lib install csu/crt1.o csu/crti.o csu/crtn.o /home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu/lib aarch64-linux-gnu-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu/lib/libc.so touch /home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/aarch64-linux-gnu/include/gnu/stubs.h
修改/home/pengdl/work/GNU/mk_cross_compiler/code/gcc-9_2_0/libsanitizer/asan/asan_linux.cc,在第77行加入如下代码:
#ifndef PATH_MAX #define PATH_MAX 4096 #endif
cd /home/pengdl/work/GNU/mk_cross_compiler/build-gcc make -j8 all-target-libgcc make install-target-libgcc
cd /home/pengdl/work/GNU/mk_cross_compiler/build-glibc make -j8 make install
cd /home/pengdl/work/GNU/mk_cross_compiler/build-gcc make -j8 make install
首先查看一下我们自己编译生成的gcc版本:
$ aarch64-linux-gnu-gcc -v Using built-in specs. COLLECT_GCC=aarch64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc/libexec/gcc/aarch64-linux-gnu/9.2.0/lto-wrapper Target: aarch64-linux-gnu Configured with: ../code/gcc-9_2_0/configure --prefix=/home/pengdl/work/GNU/mk_cross_compiler/cross-gcc --target=aarch64-linux-gnu --enable-languages=c,c++ --disable-multilib Thread model: posix gcc version 9.2.0 (GCC)
编写一个hello_world.c:
$ cat hello_world.c #include <stdio.h> int main(int argc, const char *argv[]) { printf("Hello World\n"); return 0; }
编译测试:
$ aarch64-linux-gnu-gcc --static hello_world.c -o hello_world $ qemu-aarch64 ./hello_world Hello World
完。
标签:return sub bootstra 编译 font win -- 报错 exp
原文地址:https://www.cnblogs.com/pengdonglin137/p/11565115.html