GCC Android交叉编译libgcc crtbegin_so.o crtend_so.o错误

时间:2020-05-31 21:22:13

标签: gcc cross-compiling glibc

我试图从Ubuntu 20.04 LTS(Focal Fossa)机器上为目标arm-linux-androideabi构建一个GCC交叉编译器。

Tutorial page

目标来源

binutils版本2.34。 Source

Linux内核标头版本3.10.54(我的Android设备的内核版本)Source

glibc版本2.30。 Source

GCC版本9.3.0。 Source

构建机器源

lsb_release -a

输出

Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal

lscpu

输出(我认为这很有用)

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit

binutil版本

ld -v

输出

GNU ld (GNU Binutils for Ubuntu) 2.34

Linux内核版本

uname -v

输出

5.4.0-33-generic

glibc版本

/lib/x86_64-linux-gnu/libc.so.6 -v

输出

GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9) stable release version 2.31.
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 9.3.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>

GCC版本

gcc --version

输出

gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

目录树

~/gcc-cross-build
| |-- arm-linux-androideabi
|     |-- binutils-2.34 -> *binutils source directory*
|     |-- gcc-9.3.0 -> *gcc source directory*
|     |-- glibc-2.30 -> *glibc source directory*
|     |-- linux-3.10.54 -> *Linux kernel headers source directory*
|     |-- build-binutils -> *binutils build directory*
|     |-- build-gcc -> *gcc build directory*
|     |-- build-glibc -> *glibc build directory*
|     |-- cross-gcc -> *builded gcc cross compiler files directory (prefix)*
|     |-- scripts -> *automaticly gcc cross compiler build scripts directory*
|         |-- build -> *the directory that contain the build scripts that I used here*

我的构建脚本

funcs.sh -> 功能脚本

#!/bin/bash

traps()
{
    case $1 in
        0)
            set -e
            ;;
        1)
            set +e
            ;;
        * | h)

    esac

    trap 'echo "\
###############################
ERROR  $?  $$ { $BASH_COMMAND }
*******************************
" ' ERR


    trap 'echo -n "\



({[]}) EXIT  $?  $$ { $BASH_COMMAND }



" ' EXIT

trap 'echo $BASH_COMMAND &>> ${OPDIR}/${TARGET}/scripts/build/log/commands' DEBUG


}

set_help()
{
    if !(($#==4))
    then
        echo error
        return 1
    fi
    export opt=($2)
    export opt_t=($3)
    export opt_h=($4)
    export opt_help="$(\
for i in ${!opt[@]};
do
echo -e "\t\t${opt[$i]}\t\b\b\b\b[${opt_t[$i]}]\t\b${opt_h[$i]}";
done\
)"
    export ${1}_help="\
usage $1 [option]
    available options
${opt_help}\
"
    return 0
}

vars()
{
    case $1 in
    s)
        export OPDIR=${HOME}/gcc-cross-build
        export TARGET=$2
        export PREFIX=${OPDIR}/$TARGET/cross-gcc
        export TARGET_PREFIX=$PREFIX/$TARGET
        export PATH=$PATH:$PREFIX/bin
        ;;
    u)
        unset OPDIR
        unset TARGET
        unset PREFIX
        unset TARGET_PREFIX
        export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
        ;;
    * | h)
        echo "$vars_help"
        ;;
    esac
    #. vars.sh u
    #. vars.sh s arm-linux-androideabi
}

clear_all()
{
    cd ${OPDIR}/${TARGET}
    for i in $(ls -d build-*)
    do
    rm -rfv ${i}/*
    done
    rm -rfv cross-gcc/*
}

build_binutils()
{
    cd ${OPDIR}/${TARGET}
    cd build-binutils
    ../binutils-${1}/configure --prefix=$PREFIX --target=$TARGET
    make -j4 all
    make install
}

build_linux()
{
    cd ${OPDIR}/${TARGET}
    cd linux-${1}
    make ARCH=arm INSTALL_HDR_PATH=${TARGET_PREFIX} \
    headers_install
}


build_gcc_com()
{
    cd ${OPDIR}/${TARGET}
    cd build-gcc
    ../gcc-${1}/configure --prefix=$PREFIX --target=$TARGET \
        --with-pkgversion='Alcatel Onetouch Pixi 3(10) v1' \
        --enable-languages=c,c++ --with-newlib
    make -j4 all-gcc
    make install-gcc
}

build_std_lib()
{
    cd ${OPDIR}/${TARGET}
    cd build-glibc
    ../glibc-${1}/configure --prefix=$TARGET_PREFIX --build=$MACHTYPE --host=$TARGET --target=$TARGET \
    --with-headers=${TARGET_PREFIX}/include libc_cv_forced_unwind=yes
    make install-bootstrap-headers=yes install-headers
    make install_root=${TARGET_PREFIX} prefix="" install
}

build_crt_lib()
{
    cd ${OPDIR}/${TARGET}
    cd build-glibc
    make -j4 csu/subdir_lib
    install csu/crt1.o csu/crti.o csu/crtn.o \
    ${TARGET_PREFIX}/lib
    ${TARGET}-gcc -nostdlib -nostartfiles \
    -shared -x c /dev/null -o ${TARGET_PREFIX}/lib/libc.so
    touch ${TARGET_PREFIX}/include/gnu/stubs.h
}


build_libgcc()
{
    cd ${OPDIR}/${TARGET}
    cd build-gcc
    make -j4 all-target-libgcc
    make install-target-libgcc
}

build_libc()
{
    cd ${OPDIR}/${TARGET}
    cd build-glibc
    make -j4 all
    make install
}

build_libstdc()
{
    cd ${OPDIR}/${TARGET}
    cd build-gcc
    make -j4 all
    make install
}

main.sh -> 主脚本(我运行的脚本)

#!/bin/bash

. funcs.sh

vars u

vars s arm-linux-androideabi

echo -n "" | tee ${OPDIR}/${TARGET}/scripts/build/log/commands

traps 0

set_help vars "s u" "- target" "enable_variables disable_variables"

clear_all

build_binutils 2.34 \
| tee ${OPDIR}/${TARGET}/scripts/build/log/binutils.log

build_linux 3.10.54 \
| tee ${OPDIR}/${TARGET}/scripts/build/log/linux.log

build_gcc_com 9.3.0 \
| tee ${OPDIR}/${TARGET}/scripts/build/log/gcc_com.log

build_std_lib 2.30 \
| tee ${OPDIR}/${TARGET}/scripts/build/log/std_lib.log

build_crt_lib \
| tee ${OPDIR}/${TARGET}/scripts/build/log/crt_lib.log

build_libgcc \
| tee ${OPDIR}/${TARGET}/scripts/build/log/libgcc.log

build_libc \
| tee ${OPDIR}/${TARGET}/scripts/build/log/libc.log

build_libstdc \
| tee ${OPDIR}/${TARGET}/scripts/build/log/libstdc.log

一切顺利,一切都建立起来

从build-gcc目录make all-target-libgcc

或从build-gcc / arm-linux-androideabi / libgcc目录make all

或从build-gcc / arm-linux-androideabi / armv7-a / libgcc目录make all

给出该错误

/home/home/gcc-cross-build/arm-linux-androideabi/cross-gcc/arm-linux-androideabi/bin/ld: cannot find crtbegin_so.o: No such file or directory
/home/home/gcc-cross-build/arm-linux-androideabi/cross-gcc/arm-linux-androideabi/bin/ld: cannot find crtend_so.o: No such file or directory

0 个答案:

没有答案