1、交叉编译工具链下载位置:
https://github.com/raspberrypi/ 不能下载,评论告诉我,发给你们
2、从共享文件夹拷贝到工作目录
cp /mnt/hgfs/share/tools-master.zip /home/CLC
3、解压
unzip tools-master.zip
5、检查版本gcc -v ,主要检查arm-linux-gnueabihf-gcc 交叉编译工具版本4.8.3
CLC@Embed_Learn:~/lessonPi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin$ cd
CLC@Embed_Learn:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
CLC@Embed_Learn:~$ arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/CLC/lessonPi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.03/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/home/zhehe01/work/bzr/pi-build/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03)
6、创建一个.c文件,分别用gcc和arm-linux-gnueabihf-gcc 编译,并且查看文件的可执行类型(file + 文件名)
CLC@Embed_Learn:~$ vi test7.c
CLC@Embed_Learn:~$ gcc test7.c -o one
CLC@Embed_Learn:~$ arm-linux-gnueabihf-gcc test7.c -o armOne
CLC@Embed_Learn:~$ file one
one: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x180c6c1ee033fd666d2235a65887095416530e8d, not stripped
// x86-64,指的是32、64位
CLC@Embed_Learn:~$ file armOne
armOne: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x2e52782540abf590a8129961866c5dd81b4becb4, not stripped
// 指的是executable, ARM
7、显然 arnOne是不可再Ubuntu上运行的,只能在ARM上运行(如下载到树莓派开发板上运行)
CLC@Embed_Learn:~$ ./one
Hello
CLC@Embed_Learn:~$ ./armOne
bash: ./armOne: cannot execute binary file
8、把UBuntu上的armOne文件拷贝到树莓派上
指令 文件名 开发板用户名@开发板地址:开发板的绝对路径
CLC@Embed_Learn:~$ scp armOne pi@192.168.111.1:/home/pi
The authenticity of host '192.168.124.14 (192.168.111.11)' can't be established.
ECDSA key fingerprint is f0:e9:43:8c:41:c1:db:87:6f:cc:79:56:86:00:6b:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.111.1' (ECDSA) to the list of known hosts.
pi@192.168.124.14's password:
armOne 100% 5980 5.8KB/s 00:00
CLC@Embed_Learn:~$ scp one pi@192.168.124.14:/home/pi
pi@192.168.111.1's password:
one 100% 8377 8.2KB/s 00:00
9、我们可以看到树莓派上已经存在one和armOne 文件
pi@raspberrypi:~ $ ls
armOne one Pictures Public Templates Videos
11、在树莓派上运行看看效果
pi@raspberrypi:~ $ ./one
-bash: ./one: cannot execute binary file: Exec format error
pi@raspberrypi:~ $ ./armOne
Hello
12、OK!!!
|