您的位置:首页 > 其它

linaro gcc 交叉编译链编译

2018-02-09 16:17 169 查看
linaro gcc 交叉编译链编译全解析
在此编译的是4.8.3版本的gcc,依赖2.18的glibc,2.24的binutils
参考http://blog.chinaunix.net/uid-24943863-id-3997047.html 和 CodeSourcery的编译脚本
依赖:
gmp ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2 mpfr 依赖gmp ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2 mpc 依赖mpfr,gmp ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz isl 依赖gmp ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.11.1.tar.bz2 cloog 依赖isl或者编译自带的,编译cloog自带的有可能会有和binutils需要的isl版本冲突 ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz binutils 需要依赖isl和cloog http://releases.linaro.org/archive/14.03/components/toolchain/binutils-linaro/binutils-linaro-2.24-2014.03.tar.xz kernel 作为编译glibc时需要依赖的linux头文件 https://www.kernel.org/pub/linux/kernel/   3.4.39
eglibc 需要用编译出来的交叉编译链中的gcc作为编译器 http://releases.linaro.org/archive/13.10/components/toolchain/eglibc-linaro/eglibc-linaro-2.18-2013.10.tar.bz2 gcc 依赖binutils编译出来的ar等程序 http://releases.linaro.org/archive/14.04/components/toolchain/gcc-linaro/4.8/gcc-linaro-4.8-2014.04.tar.xz 编译顺序:
gmp
mpfr
mpc
isl
cloog
binutils
gcc_first   首先静态编译出用于编译eglibc编译的gcc(这时候需要依赖libc的功能都不要选)
kernel       编译需要用到的headers
eglibc_header 初次编译再次编译gcc所依赖的libc库
gcc_second   编译可以依赖libc的动态库
eglibc      编译完整的glibc库
gcc_all     编译需要依赖glibc完整库的gcc(g++ libmudflap等)

编译平台:Ubuntu 14.04 amd64 server      I5 4G
sudo apt-get update
sudo apt-get upgrade (更新到当前版本的最新系统)
sudo apt-get install linux-generic-lts-xenial linux-headers-generic-lts-xenial linux-image-generic-lts-xenial (更新到当前版本的最新系统时提示还有几个没有更新,可以不需要)
sudo apt-get autoclean
sudo apt-get clean
需要用到编译相关的程序/库
sudo apt-get install gcc                                    
sudo apt-get install gdb
sudo apt-get install g++
sudo apt-get install pkg-config
sudo apt-get install autoconf
sudo apt-get install texinfo
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install gettext
sudo apt-get install unzip
sudo apt-get install texlive
其他
sudo apt-get install cmake
sudo apt-get install git
sudo apt-get install subversion
sudo apt-get install lib32stdc++6
sudo apt-get install lib32ncurses5
sudo apt-get install lib32bz2-1.0
sudo apt-get install lib32z1
sudo apt-get install ncurses-dev

开始构建:
设置相关的参数变量:#!/bin/bash
BUILDPKGVERSION="GCC Linaro Lite 2014.04"
#build depends
HOST_LIBS=host-libs/usr
BINUTILS_LIBS=binutils-libs/usr
GCC_LIBS=gcc-libs
TARGET=arm-linux-gnueabi
HOST_TARGET=x86_64-linux-gnu
CUR_DIR=`pwd`
SRC_DIR=${CUR_DIR}/src
BUILD_DIR=${CUR_DIR}/build
INSTALL_DIR=${CUR_DIR}/install

GMP_TAR=${CUR_DIR}/gmp-4.3.2.tar.bz2
MPFR_TAR=${CUR_DIR}/mpfr-2.4.2.tar.bz2
ISL_TAR=${CUR_DIR}/isl-0.11.1.tar.bz2
CLOOG_TAR=${CUR_DIR}/cloog-0.18.1.tar.bz2
MPC_TAR=${CUR_DIR}/mpc-0.8.1.tar.bz2
LINUX_TAR=${CUR_DIR}/kernel-3.4.39.tar.bz2
GLIBC_TAR=${CUR_DIR}/eglibc-linaro-2.18-2013.10.tar.bz2
BINUTILS_TAR=${CUR_DIR}/binutils-linaro-2.24-2014.03.tar.bz2
GCC_TAR=${CUR_DIR}/gcc-linaro-4.8-2014.04.tar.bz2
GDB_TAR=${CUR_DIR}/gdb-linaro-7.6-2013.05.tar.bz2

PROJ_NAME=arm-eglibc-linux-gnueabi
SYSROOT=sysroot

GMP_SRC=${SRC_DIR}/gmp
MPFR_SRC=${SRC_DIR}/mpfr
MPC_SRC=${SRC_DIR}/mpc
ISL_SRC=${SRC_DIR}/isl
CLOOG_SRC=${SRC_DIR}/cloog
BINUTILS_SRC=${SRC_DIR}/binutils
LINUX_SRC=${SRC_DIR}/linux
GLIBC_SRC=${SRC_DIR}/glibc
GCC_SRC=${SRC_DIR}/gcc
GDB_SRC=${SRC_DIR}/gdb

GMP_BUILD=${BUILD_DIR}/gmp
MPFR_BUILD=${BUILD_DIR}/mpfr
MPC_BUILD=${BUILD_DIR}/mpc
ISL_BUILD=${BUILD_DIR}/isl
CLOOG_BUILD=${BUILD_DIR}/cloog
BINUTILS_BUILD=${BUILD_DIR}/binutils
LINUX_BUILD=${BUILD_DIR}/linux
GLIBC_HEADER_BUILD=${BUILD_DIR}/glibc_header
GLIBC_BUILD=${BUILD_DIR}/glibc
GCC_FIRST_BUILD=${BUILD_DIR}/gcc_first
GCC_SECOND_BUILD=${BUILD_DIR}/gcc_second
GCC_THIRD_BUILD=${BUILD_DIR}/gcc_third
GDB_BUILD=${BUILD_DIR}/gdb
GDB_B_BUILD=${BUILD_DIR}/gdb_build
GDB_SERVER_BUILD=${BUILD_DIR}/gdb_server
export PATH=$PATH:${INSTALL_DIR}/${PROJ_NAME}/bin
#init src build install
init_dir()
{
rm -rf ${SRC_DIR} ${BUILD_DIR} ${INSTALL_DIR}
mkdir -p ${SRC_DIR}
mkdir -p ${BUILD_DIR}
mkdir -p ${INSTALL_DIR}
}


配置和编译需要依赖的库(gmp、mpfr等):
#编译静态库的方式,以便后面不需要把动态库包含进来
#gmp
build_gmp()
{
    tar -jxf ${GMP_TAR} -C ${SRC_DIR}
    BASENAME=`basename ${GMP_TAR} .tar.bz2`
    mv ${SRC_DIR}/${BASENAME} ${GMP_SRC}
    mkdir -p ${GMP_BUILD}
    pushd ${GMP_BUILD}
    ${GMP_SRC}/configure \
    --prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
    --build=${HOST_TARGET} --host=${HOST_TARGET} \
    --target=${HOST_TARGET} \
    --disable-shared
    make -j4 CFLAGS="-g -O2"
    make install 
    make check
    popd   
}

#mpfr
build_mpfr()
{
    tar -jxf ${MPFR_TAR} -C ${SRC_DIR}
    BASENAME=`basename ${MPFR_TAR} .tar.bz2`
    mv ${SRC_DIR}/${BASENAME} ${MPFR_SRC}
    mkdir -p ${MPFR_BUILD}
    pushd ${MPFR_BUILD}
    ${MPFR_SRC}/configure \
    --prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET} \
    --target=${TARGET} \
    --with-gmp=${INSTALL_DIR}/build/${HOST_LIBS} \
    --disable-shared 
    make -j4 CFLAGS="-g -O2"
    make install 
    make check 
    popd
}

#mpc
build_mpc()
{
    tar -jxf ${MPC_TAR} -C ${SRC_DIR}
    BASENAME=`basename ${MPC_TAR} .tar.bz2`
    mv ${SRC_DIR}/${BASENAME} ${MPC_SRC}
    mkdir -p ${MPC_BUILD}
    pushd ${MPC_BUILD}
    ${MPC_SRC}/configure \
    --prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET}  \
    --target=${TARGET} \
    --with-gmp=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpfr=${INSTALL_DIR}/build/${HOST_LIBS} \
    --disable-shared 
    make -j4 CFLAGS="-g -O2"
    make install 
    make check
    popd
}
#mpc
build_isl()
{
    tar -jxf ${ISL_TAR} -C ${SRC_DIR}
    BASENAME=`basename ${ISL_TAR} .tar.bz2`
    mv ${SRC_DIR}/${BASENAME} ${ISL_SRC}
    mkdir -p ${ISL_BUILD}
    pushd ${ISL_BUILD}
    ${ISL_SRC}/configure \
    --prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET}  \
    --target=${TARGET} \
    --with-gmp-prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
    --disable-shared 
    make -j4 CFLAGS="-g -O2"
    make install 
    make check
    popd
}
#cloog 如果没有配置isl则会编译自带的,如果上面编译了isl,这里没有进行关联,会导致isl冲突而binutils配置失败
build_cloog()
{
tar -jxf ${CLOOG_TAR} -C ${SRC_DIR}
BASENAME=`basename ${CLOOG_TAR} .tar.bz2`
mv ${SRC_DIR}/${BASENAME} ${CLOOG_SRC}
mkdir -p ${CLOOG_BUILD}
pushd ${CLOOG_BUILD}
${CLOOG_SRC}/configure \
--prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
--build=${HOST_TARGET} \
--host=${HOST_TARGET}  \
--target=${TARGET} \
--with-isl=system \
--with-isl-prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
--with-gmp-prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
--disable-shared
make -j4 CFLAGS="-g -O2"
make install
make check
popd
}

编译binutils:(不能加--enable-shared,会导致移植后使用时链接库失败)#binutils
build_binutils()
{
    tar -jxf ${BINUTILS_TAR} -C ${SRC_DIR}
    BASENAME=`basename ${BINUTILS_TAR} .tar.bz2`
    mv ${SRC_DIR}/${BASENAME} ${BINUTILS_SRC}
    mkdir -p  ${BINUTILS_BUILD}
    pushd ${BINUTILS_BUILD}
    ${BINUTILS_SRC}/configure \
    --prefix=${INSTALL_DIR}/${PROJ_NAME} \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET} \
    --target=${TARGET} \
    --disable-gdb \
    --disable-libdecnumber \
    --disable-readline \
    --disable-sim \
    --disable-nls \
    --enable-poison-system-directories \
    --enable-plugins \
    --with-float=softfp \
    --with-pkgversion="'""${BUILDPKGVERSION}""'" \
    --with-isl=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}
    make -j4 all-libiberty CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
    mkdir -p ${INSTALL_DIR}/build/${BINUTILS_LIBS}
    mkdir -p ${INSTALL_DIR}/build/${BINUTILS_LIBS}/lib
    mkdir -p ${INSTALL_DIR}/build/${BINUTILS_LIBS}/include
    mkdir -p ${INSTALL_DIR}/build/${BINUTILS_LIBS}/testbin
    cp -r ${BINUTILS_SRC}/include ${INSTALL_DIR}/build/${BINUTILS_LIBS}/include
    chmod -R u+w ${INSTALL_DIR}/build/${BINUTILS_LIBS}/include
    cp ${BINUTILS_BUILD}/libiberty/libiberty.a ${INSTALL_DIR}/build/${BINUTILS_LIBS}/lib
    make -j4 CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib includedir=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/include libdir=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib
    cp ${BINUTILS_BUILD}/bfd/.libs/libbfd.a ${INSTALL_DIR}/build/${BINUTILS_LIBS}/lib
    cp ${BINUTILS_BUILD}/bfd/bfd.h ${INSTALL_DIR}/build/${BINUTILS_LIBS}/include
    cp ${BINUTILS_SRC}/bfd/elf-bfd.h ${INSTALL_DIR}/build/${BINUTILS_LIBS}/include
    cp ${BINUTILS_BUILD}/opcodes/.libs/libopcodes.a ${INSTALL_DIR}/build/${BINUTILS_LIBS}/lib
    cp ${BINUTILS_BUILD}/binutils/bfdtest1 ${INSTALL_DIR}/build/${BINUTILS_LIBS}/testbin
    cp ${BINUTILS_BUILD}/binutils/bfdtest2 ${INSTALL_DIR}/build/${BINUTILS_LIBS}/testbin
    make install prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man datadir=${INSTALL_DIR}/${PROJ_NAME}/share CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
    ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc/configure.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/configure.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly configure
    ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc/standards.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/standards.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly standards
    rmdir ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/bfd.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly bfd
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ld.bfd
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/bin/ld.bfd
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin/ld.bfd
    popd
}编译完成,在${INSTALL_DIR}/${PROJ_NAME}/bin/目录下出现:ar、ld、as、nm等相关的应用编译linux头文件(在第一次gcc编译前后都可以):
#linux_header
#headers_install 会把kernel的版本和相关的头文件都拷贝到目标目录里
build_linux_header()
{
tar -jxf ${LINUX_TAR} -C ${SRC_DIR}
BASENAME=`basename ${LINUX_TAR} .tar.bz2`
mv ${SRC_DIR}/${BASENAME} ${LINUX_SRC}
cp -r ${LINUX_SRC} ${LINUX_BUILD}
pushd ${LINUX_BUILD}
make ARCH=arm INSTALL_HDR_PATH=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr headers_install
popd
}
编译第一次gcc:这个时候不需要用到glibc,因此只编译一个包含静态库的,不需要加--disable-shared,加了之后不会生成libgcc_eh.a(编译glibc的时候依赖),也可以后面添加ln -s libgcc.a libgcc_eh.a来手动生成
--with-newlib是关键libmudflap thread c++等都是依赖libc的,而glibc只需要用到gcc就行了
init_gcc()
{
if [ ! -d  ${GCC_SRC} ]; then
tar -jxf ${GCC_TAR} -C ${SRC_DIR}
BASENAME=`basename ${GCC_TAR} .tar.bz2`
mv ${SRC_DIR}/${BASENAME} ${GCC_SRC}
fi
}
#first_gcc
build_first_gcc()
{
    init_gcc
    mkdir -p  ${GCC_FIRST_BUILD}
    pushd ${GCC_FIRST_BUILD}
    #configure
    ${GCC_SRC}/configure \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET} \
    --target=${TARGET} \
    --prefix=${INSTALL_DIR}/${PROJ_NAME} \
    --enable-poison-system-directories \
    --enable-extra-sgxxlite-multilibs \
    --enable-lto \
    --enable-symvers=gnu \
    --enable-__cxa_atexit \
    --enable-languages=c \
    --enable-linker-build-id \
    --enable-plugin \
    --enable-gold \
    --enable-c99 \
    --enable-long-long  \
    --disable-libmudflap \
    --disable-libstdcxx-pch \
    --disable-nls \
    --disable-threads \
    --disable-decimal-float \
    --disable-libffi \
    --disable-libquadmath \
    --disable-libgomp \
    --disable-libitm \
    --disable-libatomic \
    --disable-libssp \
    --with-gnu-as \
    --with-gnu-ld \
    --without-headers \
    --with-newlib \
    --with-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}' \
    --with-pkgversion="'""${BUILDPKGVERSION}""'" \
    --with-gmp=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpfr=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpc=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-isl=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-cloog=${INSTALL_DIR}/build/${HOST_LIBS}  \
    --with-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-build-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-local-prefix=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \ 
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar \
    NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm \
    OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump \
    STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip \
    CC=${HOST_TARGET}-gcc \
    CXX=${HOST_TARGET}-g++ \
    LD=${HOST_TARGET}-ld \
    OBJCOPY=${HOST_TARGET}-objcopy \
    AR=${HOST_TARGET}-ar \
    RANLIB=${HOST_TARGET}-ranlib \
    SED=sed
    make -j4 LDFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} CPPFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} build_tooldir=${INSTALL_DIR}/${PROJ_NAME}/${TARGET} AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install-html AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install-pdf AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    popd
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccinstall ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccinstall.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccinstall.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccinstall
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccint ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccint.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccint.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccint
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/cppinternals ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/cppinternals.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/cppinternals.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly cppinternals
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/libiberty.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/libiberty.pdf
}
编译完后,在  ${INSTALL_DIR}/${PROJ_NAME}/bin目录下出现gcc等相关的应用,可以编译glibc了
编译glibc_headers:#告诉glibc依赖的linux头文件和版本信息--enable-kernel=3.4.39 --with-headers=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/include
#后面三个编译比较关键,第一个编译出相关的头文件,stdio.h等,第二个编译出在编译下一个gcc时用到的crtn.o等,第三个编译出libc.so
#--prefix不能随便写,这个路径会加到install_root后面去的,如果会导致编译后面gcc时找不到stdio.h
init_glibc()
{
if [ ! -d ${GLIBC_SRC} ]; then
tar -jxf ${GLIBC_TAR} -C ${SRC_DIR}
BASENAME=`basename ${GLIBC_TAR} .tar.bz2`
mkdir -p ${GLIBC_SRC}
cp -r ${SRC_DIR}/${BASENAME} ${GLIBC_SRC}/default
chmod -R u+w ${GLIBC_SRC}/default
fi
}

build_glibc_header()
{
init_glibc
#ln -s ${INSTALL_DIR}/${PROJ_NAME}/lib/gcc/${TARGET}/4.8.3/libgcc.a ${INSTALL_DIR}/${PROJ_NAME}/lib/gcc/${TARGET}/4.8.3/libgcc_eh.a
#ln -s ${INSTALL_DIR}/${PROJ_NAME}/lib/gcc/${TARGET}/4.8.3/${TARGET}/libgcc.a ${INSTALL_DIR}/${PROJ_NAME}/lib/gcc/${TARGET}/4.8.3/${TARGET}/libgcc_eh.a
#glibc_header1
mkdir -p ${GLIBC_HEADER_BUILD}/default
    mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/lib ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib
    pushd ${GLIBC_HEADER_BUILD}/default
    ${GLIBC_SRC}/default/configure \
    --prefix=/usr \
    --with-headers=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/include \
    --build=${HOST_TARGET} \
    --host=${TARGET} \
    --disable-profile \
    --without-gd \
    --without-cvs \
    --enable-obsolete-rpc \
    --enable-add-ons \
    --enable-kernel=2.6.16 \
    --with-pkgversion="'""${BUILDPKGVERSION}""'" \
    BUILD_CC=gcc \
    CFLAGS="-g -O2" \
    CC=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-gcc \
    AR=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar \
    NM=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm \
    RANLIB=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ranlib \
    READELF=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-readelf \
    PERL=/usr/bin/perl \
    BASH_SHELL=/bin/bash
    make install_root=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/ install-bootstrap-headers=yes install-headers CFLAGS="-g -O2"
    make csu/subdir_lib CFLAGS="-g -O2"
    cp csu/crt1.o csu/crti.o csu/crtn.o ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/
    popd
    ${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-gcc -o ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libc.so -nostdlib -nostartfiles -shared -x c /dev/null
}

编译第二次gcc:这次还是不能编c++,这个需要依赖到glibc相关的动态库,还有一些lib也是用到glibc,因此也不能包含进来,但是可以编译动态库了,强行编译会出现 C compiler cannot create executables错误,查看config.log日志可以得到引用了一些函数#gcc2
build_second_gcc()
{
    init_gcc
    mkdir -p ${GCC_SECOND_BUILD}
    pushd ${GCC_SECOND_BUILD}
    ${GCC_SRC}/configure \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET} \
    --target=${TARGET} \
    --prefix=${INSTALL_DIR}/${PROJ_NAME} \
    --enable-poison-system-directories \
    --enable-extra-sgxxlite-multilibs \
    --enable-languages=c \
    --enable-shared \
    --enable-threads=posix \
    --disable-libmudflap \
    --disable-multilib \
    --enable-lto \
    --enable-symvers=gnu  \
    --enable-__cxa_atexit  \
    --enable-linker-build-id \
    --enable-plugin \
    --enable-gold \
    --enable-c99 \
    --enable-long-long  \
    --disable-libssp \
    --disable-libgomp \
    --disable-libitm \
    --disable-libffi \
    --disable-libquadmath \
    --disable-libstdcxx-pch \
    --disable-libatomic \
    --disable-nls \
    --with-gnu-as \
    --with-gnu-ld \
    --with-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}' \
    --with-pkgversion="'""${BUILDPKGVERSION}""'" \
    --with-gmp=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpfr=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpc=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-isl=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-cloog=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-build-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-local-prefix=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \ 
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar \
    NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm \
    OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump \
    STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip \
    SED=sed
    make -j4 LDFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} CPPFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} build_tooldir=${INSTALL_DIR}/${PROJ_NAME}/${TARGET} AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install-html AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man install-pdf AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccinstall ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccinstall.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccinstall.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccinstall
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccint ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccint.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccint.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccint
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/cppinternals ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/cppinternals.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/cppinternals.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly cppinternals
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/libiberty.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/libiberty.pdf
    popd
}
第二次编译glibc(完全编译):build_glibc()
{
    init_glibc
    #glibc1
    mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/lib/ ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/
    mkdir -p ${GLIBC_BUILD}/default/
    pushd ${GLIBC_BUILD}/default/
    ${GLIBC_SRC}/default/configure \
    --prefix=/usr \
    --with-headers=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/include \
    --build=${HOST_TARGET} \
    --host=${TARGET} \
    --disable-profile \
    --without-gd \
    --without-cvs \
    --enable-obsolete-rpc \
    --enable-add-ons 
    --enable-kernel=2.6.16 \
    libc_cv_forced_unwind=yes \
    libc_cv_c_cleanup=yes \
    libc_cv_arm_tls=yes \
    --with-pkgversion= "'""${BUILDPKGVERSION}""'"\
    BUILD_CC=gcc \
    CC=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-gcc \
    CFLAGS="-g -O2" \
    AR=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar \
    NM=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm \
    RANLIB=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ranlib \
    READELF=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-readelf \
    PERL=/usr/bin/perl \
    BASH_SHELL=/bin/bash 
    make -j4 
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/info/dir ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/share/info/dir
    make install_root=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/ install
    make html
    mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html
    cp -r ${GLIBC_BUILD}/default/manual/libc ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/libc
    make pdf
    mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf
    cp ${GLIBC_BUILD}/default/manual/libc.pdf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/libc.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/pt_chown
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libc_pic
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libBrokenLocale_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libanl_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libc_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libcidn_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libcrypt_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libdl_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libm_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnsl_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_compat_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_db_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_dns_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_files_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_hesiod_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_nis_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_nisplus_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libresolv_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/librt_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libthread_db_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libutil_pic.a
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libBrokenLocale_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libanl_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libc_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libcidn_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libcrypt_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libdl_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libm_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnsl_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_compat_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_db_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_dns_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_files_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_hesiod_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_nis_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libnss_nisplus_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libresolv_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/librt_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libthread_db_pic.map
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/libutil_pic.map
    mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/sbin/ldconfig ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/sbin/sln ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/catchsegv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/gencat ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/getconf ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/getent ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/iconv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/ldd ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/locale ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/localedef ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/makedb ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/mtrace ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/pcprofiledump ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/pldd ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/rpcgen ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/sotruss ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/sprof ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/tzselect ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/xtrace ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/sbin/iconvconfig ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/sbin/nscd ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/sbin/zdump ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/sbin/zic ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/POSIX_V6_ILP32_OFF32 ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/POSIX_V6_ILP32_OFFBIG ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/POSIX_V7_ILP32_OFF32 ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/POSIX_V7_ILP32_OFFBIG ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/XBS5_ILP32_OFF32 ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/libexec/getconf/XBS5_ILP32_OFFBIG ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
    popd 
}最后一次编译gcc(这时候可以包含需要用到的相关的库和c++了):
参考了arm-cortex_a9-eabi-4.7-eglibc-2.18需要用到的libbuild_third_gcc()
{
    mkdir -p ${GCC_THIRD_BUILD}
    pushd ${GCC_THIRD_BUILD}
    ${GCC_SRC}/configure \
    --build=${HOST_TARGET} \
    --host=${HOST_TARGET} \
    --target=${TARGET} \
    --prefix=${INSTALL_DIR}/${PROJ_NAME} \
    --enable-threads \
    --enable-extra-sgxxlite-multilibs \
    --enable-poison-system-directories \
    --enable-languages=c,c++,fortran \
    --enable-shared \
    --enable-lto \
    --enable-symvers=gnu \
    --enable-__cxa_atexit \
    --enable-linker-build-id \
    --enable-plugin \
    --enable-gold \
    --enable-c99 \
    --enable-long-long  \
    --enable-libmudflap \
    --enable-libgomp \
    --enable-libitm \
    --enable-libssp \
    --disable-libstdcxx-pch \
    --disable-libatomic \
    --disable-nls \
    --with-gnu-as \
    --with-gnu-ld \
    --with-pkgversion="'""${BUILDPKGVERSION}""'" \
    --with-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}' \
    --with-gmp=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpfr=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-mpc=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-isl=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-cloog=${INSTALL_DIR}/build/${HOST_LIBS} \
    --with-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-build-sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \
    --with-local-prefix=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} \ 
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    --with-build-time-tools=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/bin \
    AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar \
    NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm \
    OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump \
    STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip \
    SED=sed
    make -j4 LDFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} CPPFLAGS_FOR_TARGET=--sysroot=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} build_tooldir=${INSTALL_DIR}/${PROJ_NAME}/${TARGET} AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip 
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip install 
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip install-html
    make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man AR_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-ar NM_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-nm OBJDUMP_FOR_TARET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-objdump STRIP_FOR_TARGET=${INSTALL_DIR}/${PROJ_NAME}/bin/${TARGET}-strip install-pdf
    popd
    pushd ${INSTALL_DIR}/${PROJ_NAME}
    rm ./lib/libiberty.a
    rmdir include
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccinstall ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccinstall.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccinstall.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccinstall
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gccint ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/gccint.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/gccint.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly gccint
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/cppinternals ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gcc/cppinternals.pdf
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/cppinternals.info
    ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly cppinternals
    rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/libiberty.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/libiberty.pdf
    rm -rf ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/lib/libstdc++.so.6.0.19-gdb.py
}
其他可选:
gdb编译build_gdb()
{
tar -jxf ${GDB_TAR} -C ${SRC_DIR}
BASENAME=`basename ${GDB_TAR} .tar.bz2`
mv ${SRC_DIR}/${BASENAME} ${GDB_SRC}
cp -r ${GDB_SRC} ${GDB_BUILD}
chmod -R u+x ${GDB_BUILD}
mkdir -p ${GDB_B_BUILD}
pushd ${GDB_B_BUILD}
${GDB_BUILD}/configure \
--prefix=/${PROJ_NAME} \
--build=${HOST_TARGET} \
--target=${TARGET} \
--host=${HOST_TARGET} \
--disable-sim \
--disable-binutils \
--disable-elfcpp \
--disable-gas \
--disable-gold \
--disable-gprof \
--disable-ld \
--disable-libmcheck \
--disable-nls \
--with-libexpat-prefix=${INSTALL_DIR}/build/${HOST_LIBS} \
--with-system-gdbinit=/${PROJ_NAME}/${HOST_TARGET}/${TARGET}/lib/gdbinit \
--with-gdb-datadir=\''${prefix}'\'"'""/${TARGET}/share/gdb""'" \
CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include \
LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
make -j4 CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
make install prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man datadir=${INSTALL_DIR}/${PROJ_NAME}/share CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man datadir=${INSTALL_DIR}/${PROJ_NAME}/share install-html CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
make prefix=${INSTALL_DIR}/${PROJ_NAME} exec_prefix=${INSTALL_DIR}/${PROJ_NAME} libdir=${INSTALL_DIR}/${PROJ_NAME}/lib htmldir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html pdfdir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info mandir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/man datadir=${INSTALL_DIR}/${PROJ_NAME}/share install-pdf CPPFLAGS=-I${INSTALL_DIR}/build/${HOST_LIBS}/include LDFLAGS=-L${INSTALL_DIR}/build/${HOST_LIBS}/lib
rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/annotate ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/annotate.pdf
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/annotate.info
ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly annotate
rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/gdbint ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/gdbint.pdf
rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/stabs ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/stabs.pdf
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/stabs.info
ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly stabs
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/configure.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc/configure.pdf
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/configure.info
ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly configure
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/standards.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc/standards.pdf
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/standards.info
ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly standards
rmdir ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/etc
rm -rf ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/html/bfd.html ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/pdf/bfd.pdf
rm -f ${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info/bfd.info
ginstall-info --infodir=${INSTALL_DIR}/${PROJ_NAME}/share/doc/${TARGET}/info --remove-exactly bfd
mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/${HOST_TARGET}/${TARGET}/include/
mv ${INSTALL_DIR}/${PROJ_NAME}/include/gdb ${INSTALL_DIR}/${PROJ_NAME}/${HOST_TARGET}/${TARGET}/include
rmdir ${INSTALL_DIR}/${PROJ_NAME}/include
rm -rf ${INSTALL_DIR}/build/gdb
mkdir -p ${INSTALL_DIR}/build/gdb
cp -a ${GDB_B_BUILD}/gdb/data-directory/python ${INSTALL_DIR}/build/gdb
popd
}

build_gdb_server() {
mkdir -p ${GDB_SERVER_BUILD}/default
pushd ${GDB_SERVER_BUILD}/default
${GDB_SRC}/gdb/gdbserver/configure --build=${HOST_TARGET} --build=${HOST_TARGET} --host=${TARGET} --prefix=/usr --disable-shared --disable-sim --disable-binutils --disable-elfcpp --disable-gas --disable-gold --disable-gprof --disable-ld --disable-libmcheck
make -j4
make DESTDIR=${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT} install
pushd ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}
mkdir -p ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
mv ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/bin/gdbserver ${INSTALL_DIR}/${PROJ_NAME}/${TARGET}/${SYSROOT}/usr/lib/bin
popd
}

最后编译完成生成的gcc就可以使用了:~/package/install/arm-eglibc-linux-gnueabi$ ./bin/arm-linux-gnueabi-gcc -o hello hello.c
:~/package/install/arm-eglibc-linux-gnueabi$ ./hello
-bash: ./hello: cannot execute binary file: Exec format error
:~/package/install/arm-eglibc-linux-gnueabi$ ./bin/arm-linux-gnueabi-readelf -h hello
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x83e0
Start of program headers: 52 (bytes into file)
Start of section headers: 5020 (bytes into file)
Flags: 0x5000202, has entry point, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 38
Section header string table index: 35

在这个过程中编译失败很多次,有 C compiler cannot create executables的,

GCC_NO_EXECUTABLES的,找不到stdio.h的,还有zlib编译失败的(由于在编译binutils设置了--disable-multilib,而编译gcc的时候enable了,因此编译失败,不知道是不这个原因)等等。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: