1、从网上下载arm-linux-gcc-4.4.3.tar.gz,解压到自己的目录下,我的目录结构/home/cyh/cyh/arm
2、建立目录
sudo mkdir /usr/local/arm
3、复制文件
sudo cp -r /home/cyh/cyh/arm/opt/FriendlyARM/toolschain/4.4.3 /usr/local/arm
4、添加环境变量
修改/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.4.3/bin”
5、重新启动电脑
6、检查路径是否添加到PATH中
echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.4.3/bin
7、测试是否安装成功
在终端中输入arm-linux-gcc -v
,如果出现以下内容证明交叉编译器安装成功。
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)
1、在/home/cyh/cyh/arm这个目录下写自己的测试程序hello.c
#include
int main(){
printf("hello world!\nI am Fern.\n");
return 0;
}
2、编译hello.c文件
arm-linux-gcc hello.c -o hello
如果出现以下的错误,说明本机是64位的,arm交叉编译环境是32位的,需要安装32位的兼容库。
error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
执行下面的命令:
apt-get install lib32ncurses5 ia32-libs
重新编译即可编译成功。
1、建立自己的目录结构/home/cyh/cyh/gem5/gem5-stable/test
2、将上述编译过的hello文件拷贝到/home/cyh/cyh/gem5/gem5-stable/test这个目录下
3、在终端输入命令,运行hello程序
./build/ARM/gem5.opt ./configs/example/se.py -c test/hello
如果出现以下的错误,说明上述编译hello.c文件需要静态编译
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled Dec 21 2016 17:39:13
gem5 started Dec 22 2016 09:48:24
gem5 executing on cyh-Lenovo
command line: ./build/ARM/gem5.opt ./configs/example/se.py -c test/hello
Global frequency set at 1000000000000 ticks per second
fatal: Object file is a dynamic executable however only static executables are supported!
Please recompile your executable as a static binary and try again.
@ cycle 0
[create:build/ARM/sim/process.cc, line 619]
Memory Usage: 635576 KBytes
4、重新编译hello.c文件
arm-linux-gcc hello.c -o hello -static
将hello替换原来/home/cyh/cyh/gem5/gem5-stable/test目录下的hello文件,在目录/home/cyh/cyh/gem5/gem5-stable下重新运行命令:./build/ARM/gem5.opt ./configs/example/se.py -c test/hello
5、运行结果:
cyh@cyh-Lenovo:~/cyh/gem5/gem5-stable$ ./build/ARM/gem5.opt ./configs/example/se.py -c test/hello
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled Dec 21 2016 17:39:13
gem5 started Dec 22 2016 10:20:47
gem5 executing on cyh-Lenovo
command line: ./build/ARM/gem5.opt ./configs/example/se.py -c test/hello
Global frequency set at 1000000000000 ticks per second
0: system.remote_gdb.listener: listening for remote gdb #0 on port 7000
**** REAL SIMULATION ****
info: Entering event queue @ 0. Starting simulation...
hello world!
I am Fern.
hack: be nice to actually delete the event here
Exiting @ tick 3318500 because target called exit()
至此,使用arm交叉编译器编译的程序可以在gem5中执行。
注意:
1、这里gem5的编译应为:scons build/ARM/gem5.opt
。
2、ARM: gem5 can model up to 64 (heterogeneous) cores of a Realview ARM platform, and boot unmodified Linux and Android with a combination of in-order and out-of-order CPUs. The ARM implementation supports 32 or 64-bit kernels and applications.
3、x86: The gem5 simulator supports a standard PC platform.