1.前言
GCC版本的差异.
root@ubuntu: gcc -v
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
root@ubuntu: arm-linux-gcc -v
gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)
root@ubuntu: arm-linux-gnueabihf-gcc -v
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)
2.脚本
下面是一个Makefile脚本一段(定义VERSION),Makefile 写法跟shell有所差别:
$(CC) -DVERSION=\""$(shell cat version)"\" -o $@ $<
3.编译错误
1.使用gcc 编译:
root@ubuntu:# make
gcc -DVERSION=\""(x86 Xinu) #51 (root@ubuntu) Mon Jun 20 21:15:05 CST 2016"\" -o main main.c
2.使用arm-linux-gcc编译:
root@ubuntu:# make
arm-linux-gcc -DVERSION=\""(x86 Xinu) #52 (root@ubuntu) Mon Jun 20 21:16:51 CST 2016"\" -o main main.c
arm-none-linux-gnueabi-gcc: Xinu): No such file or directory
arm-none-linux-gnueabi-gcc: #52: No such file or directory
arm-none-linux-gnueabi-gcc: (root@ubuntu): No such file or directory
arm-none-linux-gnueabi-gcc: Mon: No such file or directory
arm-none-linux-gnueabi-gcc: Jun: No such file or directory
arm-none-linux-gnueabi-gcc: 20: No such file or directory
arm-none-linux-gnueabi-gcc: 21:16:51: No such file or directory
arm-none-linux-gnueabi-gcc: CST: No such file or directory
arm-none-linux-gnueabi-gcc: 2016": No such file or directory
<command-line>: warning: missing terminating " character
main.c: In function 'main':
main.c:7: error: missing terminating " character
main.c:7: error: expected expression before ')' token
make: *** [main] Error 1
3.使用arm-linux-gnueabihf-gcc编译:
root@ubuntu:# make
arm-linux-gnueabihf-gcc -DVERSION=\""(x86 Xinu) #53 (root@ubuntu) Mon Jun 20 21:20:57 CST 2016"\" -o main main.c
PS:我们时常碰到这种编译器版本的问题(可以说是BUG吧)而摸不着头脑,很多时候就是这种情况。
4.执行结果
root@ubuntu:# ./main
Version : (x86 Xinu) #54 (root@ubuntu) Mon Jun 20 21:26:33 CST 2016
5.附录
1.Makefile
#
# Make the Xinu configuration program
#
VERSION_FILE = version.h
CC = arm-linux-gnueabihf-gcc #gcc #arm-linux-gcc
all : main
VERSIONS :
$(shell cat define VERSION \""`cat version`"\" > $(VERSION_FILE))
main : main.c
$(shell ./mkvers.sh)
$(CC) -DVERSION=\""$(shell cat version)"\" -o $@ $<
clean :
rm -fr main *.bak version $(VERSION_FILE)
2.main.c
#include <stdio.h>
int main ()
{
printf("Version : %s\n\r",VERSION);
}
3.mkvers.sh
if [ -f vn ]; then
expr `cat vn` + 1 > vn
else
echo 0 > vn
fi
if [ -z "$USER" ]; then
USER=`whoami`
fi
HOST=`hostname`
VN=`cat vn`
echo "(x86 Xinu) #$VN ("$USER"@"$HOST") "`date` > version