$ sudo apt-get install gcc g++ libgcc1 libg++ make gdb
我的主机环境:
Ubuntu:13.10
uname -r:3.11.0-12-generic
uname -a:Linux ubuntu 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 athlon i686 GNU/Linux
gcc -v:gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)
下面介绍如何在此基础上配置嵌入式交叉编译环境:
1.下载arm-linux-gcc-4.3.2.tgz,大约84.1M
2.解压:
tar zxvf arm-linux-gcc-4.3.2.tgz
由于解压出后是usr/local/arm/4.3.2/...,所以把arm这个文件夹移至usr/local下:
cd usr/local
sudo mv arm /usr/local
3.修改环境变量,把交叉编译器的路径加入到PATH。
方法一:修改/etc/bash.bashrc文件(此文件只对当前用户适用)
$sudo gedit /etc/bash.bashrc
在最后加上export PATH=$PATH:/usr/local/arm/4.3.2/bin
方法二:修改/etc/profile文件(此文件属于系统级别的环境变量,设置在里面的东西对所有用户适用):
$sudo gedit /etc/profile
增加路径设置,在末尾添加如下,保存/etc/profile文件:
export PATH=$PATH:/usr/local/arm/4.3.2/bin
方法三:修改/etc/environment文件
$sudo gedit /etc/environment
原文件应为PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: /usr/games“将其改为PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.3.2/bin"保存退出即可
4. 立即使新的环境变量生效,不用重启电脑:
对应方法一:$ source /root/.bashrc
对应方法二:$ source /etc/profile
方法三立即生效
5. 检查是否将路径加入到PATH:
$ echo $PATH
显示内容/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.3.2/bin 说明已经将交叉编译器的路径加入PATH。至此,交叉编译环境安装完成。
环境变量设置具体参考:http://blog.csdn.net/htttw/article/details/7220430
6. 测试是否安装成功
$ arm-linux-gcc -v
上面的命令会显示arm-linux-gcc信息和版本,这是我显示的信息:
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/julian/lite-respin/linux/src/gcc-4.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2008q3-72' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)
7.
一点说明:
编写一个hello world程序,然后:
gcc -o hello hello.c
file hello
输出:i386hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x9f648b952ec6ced3f49b0f166fde282b38eac310, not stripped
用arm-linux-gcc编译:
arm-linux-gcc -o hello hello.c
file hello
输出:armhello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
用arm-linux-gcc编译出的程序是无法运行在x86平台上的,只可以运行在arm上。