现在的位置: 首页 > 综合 > 正文

Ubuntu11.10搭建arm-linux-gcc-4.6.1交叉编译环境

2017年09月21日 ⁄ 综合 ⁄ 共 15661字 ⁄ 字号 评论关闭

编译环境:

内核名称:Linux

内核发行版:3.0.0-12-generic

内核版本:#20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011

硬件架构名称:i686

硬件平台:i386

操作系统:GNU/Linux

当前系统gcc版本号:4.6.1

在Linux中建立整个ARM交叉编译环境的整体过程为: 

1、  下载源码包

2、  建立编译目录并设置环境变量

3、  安装内核头文件

4、  安装二进制工具(binutils)

5、  建立初始编译器工具链(简版gcc)

6、  建立glibc库

7、  建立全套编译器工具链(full gcc)

8、  验证

一、下载源码包

GNU的所有源码文件都可以到这个地址下载:http://ftp.gnu.org/gnu/

Linux Kernel源代码可以去这里下载:http://www.kernel.org

mpc可以去这里下载:http://www.multiprecision.org

下载的源码包如下:

binutils-2.21.1.tar.bz2

gcc-4.6.1.tar.bz2

glibc-2.14.tar.bz2

glibc-linuxthreads-2.5.tar.bz2

glibc-ports-2.13.tar.bz2

gmp-5.0.2.tar.bz2

linux-2.6.39.tar.bz2

mpc-0.9.tar.gz

mpfr-2.4.2.tar.bz2

注:mpfr不建议使用3.0.0版本。mpfr-3.0.0有Bug,会导致gcc编译不过。

 

二、建立编译目录并设置环境变量

选定自己的工作目录,如我选择/opt/armlinux作为自己的工作目录,然后在armlinux中建立build-tools、kernel、tools三个文件夹,例:

root@ubuntu:/opt# mkdir
armlinux

root@ubuntu:/opt# cd
armlinux
/

root@ubuntu:/opt/armlinux# mkdir build-tools kernel tools

root@ubuntu:/opt/armlinux# cd build-tools/

root@ubuntu:/opt/armlinux/build-tools# mkdir build-binutils build-boot-gcc build-glibc build-gcc 

各文件夹的作用如下:

/opt/armlinux:交叉编译环境的主目录

/opt/armlinux/build-tools:存放binutils、gcc、glibc等GNU源码和用来编译这些源代码的目录

/opt/armlinux/kernel:用来存放Linux内核源代码 

/opt/armlinux/tools:用来存放编译好的交叉编译工具和库文件

/opt/armlinux/build-tools/build-binutils:编译binutils的目录

/opt/armlinux/build-tools/build-boot-gcc:编译gcc启动部分的目录

/opt/armlinux/build-tools/build-glibc:编译glibc的目录

/opt/armlinux/build-tools/build-gcc:编译整个gcc的目录

 

建立好编译目录之后便是设置环境变量,在opt目录创建arm.sh,内容如下:

#!/bin/sh

export PROJECTROOT=/opt/armlinux

export TARGET=arm-linux

export PREFIX=$PROJECTROOT/tools 

export TARGET_PREFIX=$PREFIX/$TARGET

export PATH=$PREFIX/bin:$PATH

然后设置环境变量:source arm.sh

root@ubuntu:/opt/# source arm.sh

各个环境变量的意义如下:

PROJECTROOT:整个交叉编译环境的根目录

TARGET:目标文件对应的architecture,arm-linux表示编译出来的target只能在arm architecture中运行

PREFIX:目标文件夹的路径前缀

TARGET_PREFIX:目标文件夹的路径前缀路径

PATH:可执行文件路径,这里主要指定编译工具等

 

三、安装内核头文件

将Linux内核源码解压至$PROJECTROOT/kernel目录,然后建立几个文件的符号链接,最后生成version.h文件。实例:

首先解压Linux内核源文件

root@ubuntu:/opt/armlinux/kernel# tar -jxvf linux-2.6.39.tar.bz2

root@ubuntu:/opt/armlinux/kernel# cd  /opt/armlinux/tools/

root@ubuntu:/opt/armlinux/tools# mkdir -p arm-linux/include

root@ubuntu:/opt/armlinux/tools#
cd -  (返回到/opt/armlinux/kernel目录)

root@ubuntu:/opt/armlinux/kernel# ln -s /opt/armlinux/kernel/linux-2.6.39/include/linux
/opt/armlinux/tools/arm-linux/include/linux

root@ubuntu:/opt/armlinux/kernel# ln -s /opt/armlinux/kernel/linux-2.6.39/include/asm-generic
/opt/armlinux/tools/arm-linux/include/asm-generic

root@ubuntu:/opt/armlinux/kernel# ln -s /opt/armlinux/kernel/linux-2.6.39/arch/arm/include/asm
/opt/armlinux/tools/arm-linux/include/asm (也可能是是asm-arm,示内核版本而定)

 

下面检查上面创建的符号链接是否正确。实例:

root@ubuntu:/opt/armlinux/kernel# cd /opt/armlinux/tools/arm-linux/include/

root@ubuntu:/opt/armlinux/tools/arm-linux/include# ll

asm -> /opt/armlinux/kernel/linux-2.6.39/arch/arm/include/asm/

asm-generic -> /opt/armlinux/kernel/linux-2.6.39/include/asm-generic/

linux -> /opt/armlinux/kernel/linux-2.6.39/include/linux/

有如上结果表示符号链接创建正确。

 

最后生成version.h文件。实例:

root@ubuntu:/opt/armlinux/kernel/linux-2.6.39#
cd /opt/armlinux/kernel/linux-2.6.39/

root@ubuntu:/opt/armlinux/kernel/linux-2.6.39#
make include/linux/version.h

  CHK     include/linux/version.h

  UPD     include/linux/version.h

接着进入相应目录查看version.h文件是否建立成功

 注:上述的做法理论上没什么问题,但实际操作时,如果用其他版本的linux内核可能会出现头文件包含不全的情况,这会直接导致后面编译glibc时出现未定义、未声明、缺少头文件(如asm/unistd.h)的错误。如果可能的话,建议按上述操作直接copy好用的其他交叉编译工具链中的asm-arm、asm-generic、linux目录。

 

四、安装二进制工具(binutils)

Binutils是一些二进制工具集合,其中包含了常用的一些命令。首先将binutils-2.21.1.tar.bz2解压至build-tools,然后进入build-binutils目录,配置并编译binutils,最后使用make install进行安装。实例:

root@ubuntu:/opt/armlinux/build-tools# cd /opt/armlinux/build-tools/

root@ubuntu:/opt/armlinux/build-tools# tar -jxvf binutils-2.21.1.tar.bz2

root@ubuntu:/opt/armlinux/build-tools# cd build-binutils/ (进入build-binutils目录编译binutils)

root@ubuntu:/opt/armlinux/build-tools/build-binutils# ../binutils-2.21.1/configure --target=$TARGET --prefix=$PREFIX

root@ubuntu:/opt/armlinux/build-tools/build-binutils# make

root@ubuntu:/opt/armlinux/build-tools/build-binutils# make install

 

完成后,去$PREFIX中检查一下生成的工具。实例:

root@ubuntu:/opt/armlinux/build-tools/build-binutils# cd /opt/armlinux/tools/bin

root@ubuntu:/opt/armlinux/tools/bin# ll

有如下文件:

arm-linux-addr2line*

arm-linux-ar*

arm-linux-as*

arm-linux-c++filt*

arm-linux-elfedit*

arm-linux-gprof*

 arm-linux-ld*

arm-linux-ld.bfd*

arm-linux-nm*

arm-linux-objcopy*

arm-linux-objdump*

arm-linux-ranlib*

arm-linux-readelf*

arm-linux-size*

arm-linux-strings*

arm-linux-strip*

 

这些生成的文件的作用分别为:

arm-linux-addr2line:将你要找的地址转成文件和行号,它要使用 debug 信息

arm-linux-ar:产生、修改和解开一个存档文件

arm-linux-as:GNU的汇编器

arm-linux-c++filt:C++ 和 java 中有一种重载函数,所用的重载函数最后会被编译转化成汇编的标,c++filt 就是实现这种反向的转化,根据标号得到函数名

arm-linux-elfedit:用途暂时未知

arm-linux-gprof:GNU汇编器预编译器

arm-linux-ld:GNU的连接器

arm-linux-ld.bfd:用途暂时未知

arm-linux-nm:列出目标文件的符号和对应的地址

arm-linux-objcopy:将某种格式的目标文件转化成另外格式的目标文件

arm-linux-objdump:显示目标文件的信息

arm-linux-ranlib:为一个存档文件产生一个索引,并将这个索引存入存档文件中

arm-linux-readelf:显示 elf 格式的目标文件的信息

arm-linux-size:显示目标文件各个节的大小和目标文件的大小

arm-linux-strings:打印出目标文件中可以打印的字符串,有个默认的长度,为4

arm-linux-strip:剥掉目标文件的所有的符号信息

 

注:编译过程中有可能出现的错误:

gcc -DHAVE_CONFIG_H -I.  -I. -I. -I../bfd -I./config -I./../include -I./.. -I./../bfd -DLOCALEDIR="\"/tools/cross/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -MT tc-arm.o -MD -MP -MF .deps/tc-arm.Tpo -c -o tc-arm.o `test
-f 'config/tc-arm.c' || echo './'`config/tc-arm.c

cc1: warnings being treated as errors

config/tc-arm.c: In function ‘make_mapping_symbol’:

config/tc-arm.c:2489: 警告:if 语句体为空

make[4]: *** [tc-arm.o] 错误 1  // 排错要充分利用报错信息。

make[4]: Leaving directory `/root/build/binutils-2.20_cross/gas'

make[3]: *** [all-recursive] 错误 1

make[3]: Leaving directory `/root/build/binutils-2.20_cross/gas'

make[2]: *** [all] 错误 2

make[2]: Leaving directory `/root/build/binutils-2.20_cross/gas'

make[1]: *** [all-gas] 错误 2

make[1]: Leaving directory `/root/build/binutils-2.20_cross'

make: *** [all] 错误 2

解决方案:

 1)网上说的在tc-arm.c中加个括号,没研究,可能好用;

 2)在make这一步中,可能会在编译../binutils-2.21/gas/config/tc-arm.c出现gcc把警告当成错误的错误,其原因在于编译该文件时使用了-Werror选项,解决办法是修改../binutils-2.21/gas/configure文件第10624行,把ERROR_ON_WARNING=yes改为ERROR_ON_WARNING=no,保存退出,重新执行make即可。

 3)在配置时,关闭Warning报错,也可以编译成功:(我用的是这种)

[root@localhost binutils-2.20_cross_no_2]# ./configure --target=arm-linux --disable-werror && make

参考:http://hi.baidu.com/thinke365/blog/item/0b525013fc1f095af819b853.html

 

五、建立初始编译器(简版 gcc)

Gcc是最主要的编译器。首先将gcc-4.6.1.tar.bz2解压至build-tools,然后将gmp-5.0.2.tar.bz2、mpfr-2.4.2.tar.bz2、mpc-0.9.tar.gz分别解压至gcc源码所在目录,并将目录重命名为gmp、mpfr、mpc,然后进入build-boot-gcc目录,进行编译配置,然后make all-gcc并安装,最后make all-target-gcc并安装。实例:

root@ubuntu:/opt/armlinux/build-tools# cd /opt/armlinux/build-tools/

root@ubuntu:/opt/armlinux/build-tools# tar -jxvf gcc-4.6.1.tar.bz2

root@ubuntu:/opt/armlinux/build-tools# cd gcc-4.6.1/

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# tar -jxvf mpfr-2.4.2.tar.bz2

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# mv mpfr-2.4.2/ mpfr

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# tar -jxvf gmp-5.0.2.tar.bz2

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# mv gmp-5.0.2/ gmp

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# tar -zxvf mpc-0.9.tar.gz

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# mv mpc-0.9 mpc

 

这里需要修改一下编译配置文件:/opt/armlinux/build-tools/gcc-4.6.1/gcc/config/arm/t-linux

将“TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer –fPIC”改为

“TARGET_LIBGCC2-CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D__gthr_posix_h”

 

然后便可以切换到目录build-boot-gcc进行编译了,实例:

root@ubuntu:/opt/armlinux/build-tools/gcc-4.6.1# cd /opt/armlinux/build-tools/build-boot-gcc/

root@ubuntu:/opt/armlinux/build-tools/build-boot-gcc# ../gcc-4.6.1/configure --target=$TARGET --prefix=$PREFIX --without-headers --enable-languages=c
--disable-threads --with-newlib --disable-shared --disable-libmudflap --disable-libssp

 

root@ubuntu:/opt/armlinux/build-tools/build-boot-gcc# make all-gcc

root@ubuntu:/opt/armlinux/build-tools/build-boot-gcc# make install-gcc

root@ubuntu:/opt/armlinux/build-tools/build-boot-gcc# make all-target-libgcc

root@ubuntu:/opt/armlinux/build-tools/build-boot-gcc# make install-target-libgcc

 

完成之后,$PREFIX/bin下又多了几个文件:

arm-linux-cpp*

arm-linux-gcc*

arm-linux-gcc-4.6.1*

arm-linux-gcov*

这些生成的文件的作用分别为:

arm-linux-cpp:GNU的C的预编译器

arm-linux-gcc:GNU的C语言编译器

arm-linux-gcc-4.6.1:GNU的C语言编译器,其实和arm-linux-gcc是一样的

arm-linux-gcov:gcc 的辅助测试工具,用来分析和优化程序

 

六、建立glic库

Glibc是交叉编译环境的运行库。首先将glibc-2.14.tar.bz2解压至build-tools,然后将glibc-linuxthreads-2.5.tar.bz2解压至glibc源码所在目录,将glibc-ports-2.13.tar.bz2解压至glibc源码所在目录,并重命名为ports。进入build-glibc文件夹,建立用于配置glibc的config.cache文件,然后配置并编译glibc,安装glibc,最后修改libc.so。实例:

root@ubuntu:/opt/armlinux/build-tools# cd /opt/armlinux/build-tools/

root@ubuntu:/opt/armlinux/build-tools# tar -jxvf glibc-2.14.tar.bz2

root@ubuntu:/opt/armlinux/build-tools# cd glibc-2.14/

root@ubuntu:/opt/armlinux/build-tools/glibc-2.14# tar -jxvf glibc-linuxthreads-2.5.tar.bz2

root@ubuntu:/opt/armlinux/build-tools/glibc-2.14# tar -jxvf glibc-ports-2.13.tar.bz2

root@ubuntu:/opt/armlinux/build-tools/glibc-2.14# mv glibc-ports-2.13/ ports

root@ubuntu:/opt/armlinux/build-tools/glibc-2.14# cd ../build-glibc/

 

创建用于配置glibc的config.cache文件,文件内容为:

libc_cv_forced_unwind=yes

libc_cv_c_cleanup=yes

libc_cv_arm_tls=yes

注:在编译过程中可能会发现本应自动生成的posix/config-name.h并没有自动生成,找不到config-name.h这个文件。这个文件是用来编译uname的。暂时没办法让它自动生成,只好自己比照uname-a的信息建一个config-name.h文件:

在build-glibc目录下建立一个posix目录

# vim build-glibc/posix/config-name.h

在vim编辑器里输入:

/* This file is generated by ../scripts/config-uname.sh.  DO NOT EDIT.

   This is used only by the generic uname function for systems with no real

   uname call.  If this data is not correct, it does not matter much.  */

#ifdef config_name_h

#define config_name_h

 

#define UNAME_SYSNAME “Linux”

#define UNAME_RELEASE “3.0.0-12-generic”

#define UNAME_VERSION “#20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011”

#define UNAME_MACHINE “i686”

 

#endif /* config_name_h */

 

建立完成之后,便可以开始配置并编译glibc了,实例:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# BUILD_CC="gcc" CC=$TARGET-gcc ../glibc-2.14/configure --host=$TARGET --target=$TARGET --prefix=/usr
--enable-add-ons --disable-profile --cache-file=config.cache --with-binutils=$PREFIX/bin/ --with-headers=$TARGET_PREFIX/include/ 

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错解决方案:

(1)checking for suffix of object files... configure: error: in `/opt/armlinux/build-tools/build-glibc':

configure: error: cannot compute suffix of object files: cannot compile

See `config.log' for more details

## ----------- ##

## Core tests. ##

## ----------- ##

 

configure:2363: checking build system type

configure:2377: result: x86_64-unknown-linux-gnu

configure:2397: checking host system type

configure:2410: result: arm-unknown-linux-gnu

configure:2439: checking for arm-linux-gcc

configure:2466: result: arm-linux-gcc

configure:2735: checking for C compiler version

configure:2744: arm-linux-gcc --version >&5

../glibc-2.14/configure: line 2746: arm-linux-gcc: command not found

configure:2755: $? = 127

configure:2744: arm-linux-gcc -v >&5

../glibc-2.14/configure: line 2746: arm-linux-gcc: command not found

configure:2755: $? = 127

configure:2744: arm-linux-gcc -V >&5

../glibc-2.14/configure: line 2746: arm-linux-gcc: command not found

configure:2755: $? = 127

configure:2744: arm-linux-gcc -qversion >&5

../glibc-2.14/configure: line 2746: arm-linux-gcc: command not found

configure:2755: $? = 127

configure:2760: checking for suffix of object files

configure:2782: arm-linux-gcc -c conftest.c >&5

../glibc-2.14/configure: line 2784: arm-linux-gcc: command not found

configure:2786: $? = 127

configure: failed program was:

| /* confdefs.h */

| #define PACKAGE_NAME "GNU C Library"

| #define PACKAGE_TARNAME "c-library"

| #define PACKAGE_VERSION "(see version.h)"

| #define PACKAGE_STRING "GNU C Library (see version.h)"

| #define PACKAGE_BUGREPORT "glibc"

| #define PACKAGE_URL "http://www.gnu.org/software/c-library/"

 

解决方法:PATH=$PREFIX/bin:$PATH ../glibc-2.14/configure BUILD_CC="gcc" CC=arm-linux-gcc --host=$TARGET --target=$TARGET --prefix=/usr --enable-add-ons --disable-profile --cache-file=config.cache --with-binutils=$PREFIX/bin/ --with-headers=$TARGET_PREFIX/include/
,在配置前面加上PATH=$PREFIX/bin:$PATH ,虽然你可能已加到bash.bashrc或/etc/profile,即将编译成的arm-linux-gcc设置了环境变量,用arm-linux-gcc -v检查发现已存在,但就是不好使,编译会报错(上述),故在配置前面加上此句。

 

(2)[ALL ]     mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed (bad class -- [], [^] or [)

   [ALL ]     /[^

   [ALL ]     mawk: scripts/gen-sorted.awk: line 19: syntax error at or near ]

   [ALL ]     mawk: scripts/gen-sorted.awk: line 19: runaway regular expression /, "", subd ...

在gen-sorted.awk第19行,出错,这是一个简单的错误,缺少了转义符

解决办法:

  查找一个看有没有类似的

  cd /tmp/crosstool-ng/targets/src/glibc-cvs-2.9/scripts

sed '/\^\//p' gen-sorted.awk -n

输出的则是存在语法错误的语句

可以直接用

sed -i 's/\^\//\^\\\//g' gen-sorted.awk

  这种方法不完善,后面的还是会出现错误。

网上搜了下,需要用/usr/bin/gawk 替换/usr/bin/mawk,即

   sudo apt-get install gawk

   cd /usr/bin

   sudo mv mawk mawk.bak

   sudo ln -s gawk mawk

 

(3)../ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S:30: Error: previous CFI entry not closed (missing .cfi_endproc)

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S

找到如下行:

ENTRY(__default_sa_restorer)

在其下添加:

END(__default_sa_restorer)

找到如下行:

ENTRY(__default_rt_sa_restorer)

在其下添加:

END(__default_rt_sa_restorer)

 

(4)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错:

../sysdeps/unix/syscall-template.S:82: Error: CFI instruction used without previous .cfi_startproc

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/sysdeps/unix/syscall-template.S

找到如下行:

 

#define T_PSEUDO(SYMBOL, NAME, N)                PSEUDO (SYMBOL, NAME, N)

在其上添加:

#define PSEUDO(name, syscall_name, args)   \

  .text;                                \

  ENTRY (name);                        \

    DO_CALL (syscall_name, args);         \

    cmn r0, $4096;

(5)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错:

allocatestack.c:247:33: 错误:‘TLS_DTV_UNALLOCATED’未声明(在此函数内第一次使用)

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/nptl/allocatestack.c

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/elf/dl-tls.c

分别在文件中的include后面添加:

#define TLS_DTV_UNALLOCATED      ((void *) -1l)

(6)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错:

/opt/armlinux/tools/lib/gcc/arm-linux/4.6.1/../../../../arm-linux/bin/ld: cannot find -lgcc_eh

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# ln -s /opt/armlinux/tools/lib/gcc/arm-linux/4.6.1/libgcc.a
/opt/armlinux/tools/lib/gcc/arm-linux/4.6.1/libgcc_eh.a

(7)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错:

../sysdeps/ieee754/dbl-64/s_fma.c:152:15: 错误:‘FE_TOWARDZERO’未声明(在此函数内第一次使用)

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/sysdeps/ieee754/dbl-64/s_fma.c

在文件中的include后面添加:

#define FE_TOWARDZERO 0xc00000

#define FE_INEXACT 16

(8)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

编译出错:

../sysdeps/ieee754/dbl-64/s_fmaf.c:39:15: 错误:‘FE_TOWARDZERO’未声明(在此函数内第一次使用)

解决方法:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# vi ../glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c

在文件中的include后面添加:

#define FE_TOWARDZERO 0xc00000

#define FE_INEXACT 16

(9)继续make编译

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make

root@ubuntu:/opt/armlinux/build-tools/build-glibc# make install_root=$TARGET_PREFIX prefix="" install

 

(10)最后,修改libc.so便完成此步骤

root@ubuntu:/opt/armlinux/build-tools/build-glibc# cd /opt/armlinux/tools/arm-linux/lib

root@ubuntu:/opt/armlinux/tools/arm-linux/lib#
vim libc.so

找到如下行:

GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.2 ) )

将其改为: 

GROUP ( libc.so.6 libc_nonshared.a ) 

 

七、建立全套编译器(full gcc)

首先进入build-gcc目录,然后配置并编译full gcc,最后安装就完成了。实例:

root@ubuntu:/opt/armlinux/build-tools/build-glibc# cd /opt/armlinux/build-tools/build-gcc/

root@ubuntu:/opt/armlinux/build-tools/build-gcc# ../gcc-4.6.1/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --disable-libgomp

root@ubuntu:/opt/armlinux/build-tools/build-gcc# make

root@ubuntu:/opt/armlinux/build-tools/build-gcc# make install 

完成之后,$PREFIX/bin下又多了几个文件:

 arm-linux-c++*

arm-linux-g++*

这些生成的文件的作用分别为:

arm-linux-g++:GNU的c++编译器

arm-linux-c++:等同于arm-linux-g++

 

八、验证

使用vim编写一个简单文件,这里以hello.c为例:

然后执行编译命令:

root@ubuntu:/opt/armlinux/tmp# arm-linux-gcc -static hello.c –o hello

编译完成后验证最终编译出的文件。实例:

root@ubuntu:/opt/armlinux/tmp# file hello 

hello: ELF 32-bit LSB executable, ARM, version 1, statically linked, for GNU/Linux 2.0.0, not stripped

有如上输出表示编译ARM版本程序成功。

参考文献:http://my.oschina.net/u/225867/blog/38473

抱歉!评论已关闭.