构建 ARM GNU 交叉编译器

发布于 2024-07-30 00:04:57 字数 2781 浏览 14 评论 0原文

此处有一篇类似的(描述性较少的)帖子。

我正在尝试使用 Ubuntu 上的最新版本来推出自己的工具链,并希望这里有足够多的 Linux 社区,以便我可以在出现某些问题时获得具体建议。

在大家的帮助下,我希望看到这篇文章最终成为有用的参考。

首先,几乎每个人都提到的“Crosstool”有点过时了(2006)并且“Crosstool-NG" 现在似乎正在携带火炬,但在我的机器上失败了。 我宁愿调试进程本身而不是脚本(这似乎需要我理解该进程)。

以下是我迄今为止所做工作的基本步骤; 目前我正试图编译第一遍 GCC。

失败的地方...

失败是因为缺少包含“crti.o”的交叉编译库:

# ./gcc-4.4.1/configure --target=arm-linux --disable-thread --enable-langauges=c 
/bin/bash ../../../gcc-4.4.1/libgcc/../mkinstalldirs .
/usr/src/gnu-4.4.1-build/./gcc/xgcc -B ........
/usr/local/arm-linux/bin/ld: crti.o No such file: No such file or directory
collect2: ld returned 1 exit status
make[2]: *** [libgcc_s.so] Error 1
make[2]: Leaving directory `/usr/src/gnu/gcc-4.4.1-build/arm-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/usr/src/gnu/gcc-4.4.1-build'
make: *** [all] Error 2

构建步骤

在“新鲜​​”上配置了 Ubuntu 9.04 安装,以下是我到目前为止所做的步骤:

#New configuration of Ubuntu 9.04
sudo updatedb
sudo apt-get install build-essential subversion
# For kernel configuration
sudo apt-get install libncurses5-dev
# For building GCC
sudo apt-get install libgmp3-dev libmpfr-dev

#Get Linux Headers for GCC/GLIBC compilations
# I use a hacked Linux from Artilla, 
pushd ~ && svn co http://.../linux m501-linux && cd !$
make ARCH=arm m501_defconfig
make ARCH=arm menuconfig
sudo mkdir /usr/local/arm-linux/include
sudo cp -dR include/asm-arm /usr/local/arm-linux/include/asm
sudo cp -dR include/linux /usr/local/arm-linux/include/linux
cd /usr/local/arm-linux/
sudo ln -s include sys-include
popd

#Get sources:
cd /usr/src/
sudo su root
mkdir gnu
ftp ftp.gnu.org
# get gnu/binutils/binutils-2.19.1.tar.bz2
# get gnu/gcc/gcc-4.4.1/gcc-4.4.1.tar.bz2
# get gnu/glibc/glibc-2.10.1.tar.bz2
# get gnu/gdb/gdb-6.8.tar.bz2

#Build Binutils
bzcat binutils-2.19.1.tar.bz2 | tar -xv
mkdir binutils-2.19.1-build && cd !$
cp ../binutils-2.19.1/gas/config/tc-arm.c ./tc-arm.c 
sed -r 's/(as_bad[ \t]*\()(.+\[.+\]\))/\1\"%s\",\2/' < ./tc-arm.c > ../binutils-2.19.1/gas/config/tc-arm.c 
rm ./tc-arm.c    
../binutils-2.19.1/configure --target=arm-linux
make && make install && cd ..

#Build GCC
bzcat gcc-4.4.1.tar.bz2 | tar -xv
mkdir gcc-4.4.1-build && cd !$
../gcc-4.4.1/configure --target=arm-linux --disable-thread --enable-langauges=c -with-headers=/usr/local/arm-linux/include
make

A similiar (less descriptive) post is here.

I'm trying to roll my own tool chain using recent releases on Ubuntu and was hoping there was enough of a Linux community here that I could get specific advice on certain problems as they come up.

With everyone's help I'd like to see this turn into a useful reference eventually.

First off "Crosstool" to which nearly everyone refers is a little (2006) out of date and "Crosstool-NG" which seems to now be carrying the torch fails on my machine. I'd rather debug the process itself than a script (which it would seem requires me to understand the process).

Below are basic steps of what I've got working so far; at present I'm stuck trying to compile the first pass GCC.

Where it's failing ...

It's failing because the cross compiled library containing "crti.o" is missing:

# ./gcc-4.4.1/configure --target=arm-linux --disable-thread --enable-langauges=c 
/bin/bash ../../../gcc-4.4.1/libgcc/../mkinstalldirs .
/usr/src/gnu-4.4.1-build/./gcc/xgcc -B ........
/usr/local/arm-linux/bin/ld: crti.o No such file: No such file or directory
collect2: ld returned 1 exit status
make[2]: *** [libgcc_s.so] Error 1
make[2]: Leaving directory `/usr/src/gnu/gcc-4.4.1-build/arm-linux/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/usr/src/gnu/gcc-4.4.1-build'
make: *** [all] Error 2

Build steps

On a 'freshly' configured Ubuntu 9.04 installation, here are the steps I've done so far:

#New configuration of Ubuntu 9.04
sudo updatedb
sudo apt-get install build-essential subversion
# For kernel configuration
sudo apt-get install libncurses5-dev
# For building GCC
sudo apt-get install libgmp3-dev libmpfr-dev

#Get Linux Headers for GCC/GLIBC compilations
# I use a hacked Linux from Artilla, 
pushd ~ && svn co http://.../linux m501-linux && cd !$
make ARCH=arm m501_defconfig
make ARCH=arm menuconfig
sudo mkdir /usr/local/arm-linux/include
sudo cp -dR include/asm-arm /usr/local/arm-linux/include/asm
sudo cp -dR include/linux /usr/local/arm-linux/include/linux
cd /usr/local/arm-linux/
sudo ln -s include sys-include
popd

#Get sources:
cd /usr/src/
sudo su root
mkdir gnu
ftp ftp.gnu.org
# get gnu/binutils/binutils-2.19.1.tar.bz2
# get gnu/gcc/gcc-4.4.1/gcc-4.4.1.tar.bz2
# get gnu/glibc/glibc-2.10.1.tar.bz2
# get gnu/gdb/gdb-6.8.tar.bz2

#Build Binutils
bzcat binutils-2.19.1.tar.bz2 | tar -xv
mkdir binutils-2.19.1-build && cd !$
cp ../binutils-2.19.1/gas/config/tc-arm.c ./tc-arm.c 
sed -r 's/(as_bad[ \t]*\()(.+\[.+\]\))/\1\"%s\",\2/' < ./tc-arm.c > ../binutils-2.19.1/gas/config/tc-arm.c 
rm ./tc-arm.c    
../binutils-2.19.1/configure --target=arm-linux
make && make install && cd ..

#Build GCC
bzcat gcc-4.4.1.tar.bz2 | tar -xv
mkdir gcc-4.4.1-build && cd !$
../gcc-4.4.1/configure --target=arm-linux --disable-thread --enable-langauges=c -with-headers=/usr/local/arm-linux/include
make

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

奶茶白久 2024-08-06 00:05:06

这有点转移注意力。 显然,使用可用的 GLIBC 交叉编译现有系统的工具链不需要重新编译 GLIBC。 老实说,我不知道我是如何忽视这个事实的。

因此,尽管我仍然不知道如何交叉编译 GCC 和 GLIBC,但因为我只需要 GCC,所以我会将其标记为已关闭。

如果可以的话,我会回到这篇文章并标记我最终做了什么。

编辑:

签出这个

This was a bit of red-herring. Apparently cross-compling a tool chain for an existing system with a working GLIBC doesn't require GLIBC to be recompiled. I honestly don't know how I ignored this fact.

So even though I still don't know how to cross compile GCC and GLIBC, as I only need GCC I'm going to mark this as closed.

If I can, I'll come back to this post and mark what I eventually did.

EDIT:

Checkout this.

迟月 2024-08-06 00:05:05

我很幸运地使用 buildroot 构建用于交叉编译 Linux 的工具链和库。 Buildroot 使用轻量级 uclibc C 库而不是 glibc,因此它可能无法满足您的目的。 (以这种方式获取工具链可能不像自己编译那么令人兴奋。)

I've had good luck using buildroot to build toolchains and libraries for cross-compiling Linux. Buildroot uses the lightweight uclibc C library rather than glibc, so it might not work for your purposes. (And getting the toolchain this way might not be quite as exciting and compiling it yourself.)

猥琐帝 2024-08-06 00:05:04

如果您确实想为自己构建整个工具链:
http://frank.harvard.edu/~coldwell/toolchain/
http://ftp.snapgear。 org/pub/snapgear/tools/arm-linux/build-arm-linux-3.4.4
但请记住,您应该搜索工具链兼容性矩阵,否则可能会遇到奇怪的编译错误。

如果您仍然可以选择 crosstool-ng,这就是我最近几天正在研究的内容:
http://blog.stranadurakov.com/2009/08 /04/如何arm-linux/
在这里你会找到我的 crosstool-ng 配置文件,它对我有用。

If you're really want to build entire toolchain for yourself:
http://frank.harvard.edu/~coldwell/toolchain/
http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/build-arm-linux-3.4.4
Take in mind, though, as you should search for toolchain compatibilty matrix or you may run into weird compilation errors.

If you still have the option for crosstool-ng, this is what I'm was working on for last few days:
http://blog.stranadurakov.com/2009/08/04/how-to-arm-linux/
Here you will find my crosstool-ng configuration file, which had worked for me.

§普罗旺斯的薰衣草 2024-08-06 00:05:03

我最近使用 crosstool-ng 为 ARM 构建了一个 GNU 工具链。 我花了一些尝试和错误才弄清楚哪些版本的工具链组件可以很好地协同工作,但我最终让它与以下版本一起工作:

  • binutils 2.19.1
  • gcc 4.3.2
  • gmp 4.2.2
  • linux kernel 2.6.29.1
  • mpfr 2.3.1
  • uClibc 0.9.30.1

看看这些是否也适合您。

此外,OpenWrt 作为其构建过程的一部分,创建了一个交叉编译工具链。 即使您对制作无线路由器不感兴趣,您也可能想尝试一下,选择一块基于 ARM 的板作为目标。

I recently built a GNU toolchain for ARM using crosstool-ng. It took a bit of trial and error to figure out which versions of the toolchain components would play nice together, but I finally got it working with the following versions:

  • binutils 2.19.1
  • gcc 4.3.2
  • gmp 4.2.2
  • linux kernel 2.6.29.1
  • mpfr 2.3.1
  • uClibc 0.9.30.1

See if these work for you too.

Also, OpenWrt as a part of it's build process creates a cross-compiling toolchain. You may want to try that, selecting one of the ARM-based boards as a target, even if you aren't interested in making a wireless router.

弥繁 2024-08-06 00:05:02

您确实应该在使用 crosstool-NG 上付出更多努力,因为 crosstool 邮件列表非常活跃。 由于理解整个过程是一项艰巨的任务,因此理解如何使用可能重用的工具恕我直言更有趣。

You should really have put more effort with using crosstool-NG, since the crosstool mailing list is very reactive. Since understanding the whole process is a huge task, understanding how to use a tool that you might reuse is IMHO more interesting.

花辞树 2024-08-06 00:05:01

这是 HelenOS arm-32 工具链安装脚本,这应该可以轻松完成您想要的操作。 我现在在 Ubuntu 上使用它(我是 HelenOS 开发人员之一)。 它是由 Martin Decky 编写的:

#!/bin/bash

# Cross-Compiler Toolchain for ${PLATFORM}
#  by Martin Decky <[email protected]>
#
#  GPL'ed, copyleft
#


check_error() {
    if [ "$1" -ne "0" ]; then
        echo
        echo "Script failed: $2"
        exit
    fi
}

if [ -z "${CROSS_PREFIX}" ] ; then
    CROSS_PREFIX="/usr/local"
fi

BINUTILS_VERSION="2.19.1"
GCC_VERSION="4.3.3"

BINUTILS="binutils-${BINUTILS_VERSION}.tar.gz"
GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"

BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"

PLATFORM="arm"
WORKDIR=`pwd`
TARGET="${PLATFORM}-linux-gnu"
PREFIX="${CROSS_PREFIX}/${PLATFORM}"
BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
OBJDIR="${WORKDIR}/gcc-obj"

echo ">>> Downloading tarballs"

if [ ! -f "${BINUTILS}" ]; then
    wget -c "${BINUTILS_SOURCE}${BINUTILS}"
    check_error $? "Error downloading binutils."
fi
if [ ! -f "${GCC_CORE}" ]; then
    wget -c "${GCC_SOURCE}${GCC_CORE}"
    check_error $? "Error downloading GCC Core."
fi
if [ ! -f "${GCC_OBJC}" ]; then
    wget -c "${GCC_SOURCE}${GCC_OBJC}"
    check_error $? "Error downloading GCC Objective C."
fi
if [ ! -f "${GCC_CPP}" ]; then
    wget -c "${GCC_SOURCE}${GCC_CPP}"
    check_error $? "Error downloading GCC C++."
fi

echo ">>> Creating destionation directory"
if [ ! -d "${PREFIX}" ]; then
    mkdir -p "${PREFIX}"
    test -d "${PREFIX}"
    check_error $? "Unable to create ${PREFIX}."
fi

echo ">>> Creating GCC work directory"
if [ ! -d "${OBJDIR}" ]; then
    mkdir -p "${OBJDIR}"
    test -d "${OBJDIR}"
    check_error $? "Unable to create ${OBJDIR}."
fi

echo ">>> Unpacking tarballs"
tar -xvzf "${BINUTILS}"
check_error $? "Error unpacking binutils."
tar -xvjf "${GCC_CORE}"
check_error $? "Error unpacking GCC Core."
tar -xvjf "${GCC_OBJC}"
check_error $? "Error unpacking GCC Objective C."
tar -xvjf "${GCC_CPP}"
check_error $? "Error unpacking GCC C++."

echo ">>> Compiling and installing binutils"
cd "${BINUTILSDIR}"
check_error $? "Change directory failed."
./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" "--disable-nls"
check_error $? "Error configuring binutils."
make all install
check_error $? "Error compiling/installing binutils."

echo ">>> Compiling and installing GCC"
cd "${OBJDIR}"
check_error $? "Change directory failed."
"${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared
check_error $? "Error configuring GCC."
PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
check_error $? "Error compiling/installing GCC."

echo
echo ">>> Cross-compiler for ${TARGET} installed."

抱歉,有任何换行,应该很容易修复。 如果您想要一个 Pastebin 或 http 链接来获取它,只需发表评论。

Here is the HelenOS arm-32 toolchain installation script, this should do what you want with very little fiddling. I'm using it on Ubuntu now (I'm one of the HelenOS developers). It was written by Martin Decky:

#!/bin/bash

# Cross-Compiler Toolchain for ${PLATFORM}
#  by Martin Decky <[email protected]>
#
#  GPL'ed, copyleft
#


check_error() {
    if [ "$1" -ne "0" ]; then
        echo
        echo "Script failed: $2"
        exit
    fi
}

if [ -z "${CROSS_PREFIX}" ] ; then
    CROSS_PREFIX="/usr/local"
fi

BINUTILS_VERSION="2.19.1"
GCC_VERSION="4.3.3"

BINUTILS="binutils-${BINUTILS_VERSION}.tar.gz"
GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"

BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"

PLATFORM="arm"
WORKDIR=`pwd`
TARGET="${PLATFORM}-linux-gnu"
PREFIX="${CROSS_PREFIX}/${PLATFORM}"
BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
OBJDIR="${WORKDIR}/gcc-obj"

echo ">>> Downloading tarballs"

if [ ! -f "${BINUTILS}" ]; then
    wget -c "${BINUTILS_SOURCE}${BINUTILS}"
    check_error $? "Error downloading binutils."
fi
if [ ! -f "${GCC_CORE}" ]; then
    wget -c "${GCC_SOURCE}${GCC_CORE}"
    check_error $? "Error downloading GCC Core."
fi
if [ ! -f "${GCC_OBJC}" ]; then
    wget -c "${GCC_SOURCE}${GCC_OBJC}"
    check_error $? "Error downloading GCC Objective C."
fi
if [ ! -f "${GCC_CPP}" ]; then
    wget -c "${GCC_SOURCE}${GCC_CPP}"
    check_error $? "Error downloading GCC C++."
fi

echo ">>> Creating destionation directory"
if [ ! -d "${PREFIX}" ]; then
    mkdir -p "${PREFIX}"
    test -d "${PREFIX}"
    check_error $? "Unable to create ${PREFIX}."
fi

echo ">>> Creating GCC work directory"
if [ ! -d "${OBJDIR}" ]; then
    mkdir -p "${OBJDIR}"
    test -d "${OBJDIR}"
    check_error $? "Unable to create ${OBJDIR}."
fi

echo ">>> Unpacking tarballs"
tar -xvzf "${BINUTILS}"
check_error $? "Error unpacking binutils."
tar -xvjf "${GCC_CORE}"
check_error $? "Error unpacking GCC Core."
tar -xvjf "${GCC_OBJC}"
check_error $? "Error unpacking GCC Objective C."
tar -xvjf "${GCC_CPP}"
check_error $? "Error unpacking GCC C++."

echo ">>> Compiling and installing binutils"
cd "${BINUTILSDIR}"
check_error $? "Change directory failed."
./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" "--disable-nls"
check_error $? "Error configuring binutils."
make all install
check_error $? "Error compiling/installing binutils."

echo ">>> Compiling and installing GCC"
cd "${OBJDIR}"
check_error $? "Change directory failed."
"${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared
check_error $? "Error configuring GCC."
PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
check_error $? "Error compiling/installing GCC."

echo
echo ">>> Cross-compiler for ${TARGET} installed."

Sorry for any line wrapping, should be easy to fix. If you want a pastebin or http link to get it, just leave a comment.

蓝天 2024-08-06 00:04:59

欢迎,你并不孤单。

故事

我不知道为什么ARM交叉编译是一场噩梦。 这不是我的看法,看看其他人怎么说...

构建 gcc / glibc 交叉工具链
用于嵌入式系统
发展曾经是一件可怕的事
前景,需要钢铁般的意志,如果
不需要几周的努力,大量的 Unix 和
Gnu 知识,有时也愿意
采取狡猾的捷径。 ( http://www.kegel.com/crosstool/ )

我的 ARM 计算机 (GuruPlug) 在 Debian 上运行,所以我只需要一个标准的 G++ 编译器,无需任何调整。

我在笔记本上使用 32 位 Ubuntu。 有用于 AVR 交叉编译器的 deb 软件包,甚至有用于 Z80 的 deb 软件包,但没有用于 ARM 的 deb 软件包 - 为什么? 好的,我们必须编译一个。 我们走吧。 工具链的编译过程让我有点困惑。 14k 行长的 Makefile,谢谢。

经过几天(和几夜)我失败了。

解决方案

最后,我找到了一个现成的解决方案。 我刚刚下载了这个东西的精简版: http://www.codesourcery.com/ sgpp/lite_edition.html 现在我很高兴。 它的安装程序很丑陋,但它可以工作。 它说:
arm-none-linux-gnueabi-g++ (Sourcery G++ Lite 2010q1-202) 4.4.1,这是最新的 G++ 版本。

(我的朋友有一台Mac,他在与它纠缠了一个星期后也无法编译工具链。他现在在运行Ubuntu的VM上使用这个编译器。)

Welcome, you're not alone.

The story

I don't know why ARM cross-compiling is such a nightmare. It's not my opinion, let's see, what others say...

Building a gcc / glibc cross-toolchain
for use in embedded systems
development used to be a scary
prospect, requiring iron will, days if
not weeks of effort, lots of Unix and
Gnu lore, and sometimes willingness to
take dodgy shortcuts. ( http://www.kegel.com/crosstool/ )

My ARM computer (GuruPlug) is running on Debian, so I just need a standard G++ compiler, without any tweaks.

I'm using 32-bit Ubuntu on my notebook. There are deb packages for AVR cross-compiler, or even for Z80, but none for ARM - why? OK, we have to compile one. Let's go. The compilation process of the toolchain is a bit confusing for me. 14k lines long Makefile, thank you.

After some days (and nights) I've failed.

The solution

Finally, I've found an out-of-the box soluion. I've just downloaded the lite edition of this stuff: http://www.codesourcery.com/sgpp/lite_edition.html and now I'm happy. It has an ugly installer, but it works. It says:
arm-none-linux-gnueabi-g++ (Sourcery G++ Lite 2010q1-202) 4.4.1, which is an up-to-date G++ version.

(My friend has a Mac, and he has also failed compiling the toolchain after fighting with it for a week. He is now using this compiler on a VM running Ubuntu.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文