接上文,修改Makefile和config.mk中,.depend相关文件格式后继续编译。
四、tools文件夹的文件编译错误
错误告警如下【多行信息,请使用右侧滚动条查看】:
1 gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -idirafter /u-boot-2010.09/u-boot-2010.09/include -idirafter /u-boot-2010.09/u-boot-2010.09/include2 -idirafter /u-boot-2010.09/u-boot-2010.09/include -I /u-boot-2010.09/u-boot-2010.09/lib/libfdt -I /u-boot-2010.09/u-boot-2010.09/tools -DTEXT_BASE=0x11080000 -DUSE_HOSTCC -D__KERNEL_STRICT_NAMES -ansi -o default_image.o default_image.c -c 2 In file included from fdt_host.h:25:0, 3 from mkimage.h:35, 4 from default_image.c:30: 5 ../include/libfdt.h:126:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 6 ../include/libfdt.h:162:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 7 ../include/libfdt.h:163:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 8 ../include/libfdt.h:164:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 9 ../include/libfdt.h:165:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 10 ../include/libfdt.h:166:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 11 ../include/libfdt.h:167:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 12 ../include/libfdt.h:168:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 13 ../include/libfdt.h:169:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 14 ../include/libfdt.h:170:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 15 ../include/libfdt.h:171:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 16 ../include/libfdt.h:390:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’ 17 ../include/libfdt.h:441:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 18 ../include/libfdt.h:779:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 19 ../include/libfdt.h:845:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 20 ../include/libfdt.h:995:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 21 In file included from default_image.c:31:0: 22 /u-boot-2010.09/u-boot-2010.09/include/image.h:355:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 23 /u-boot-2010.09/u-boot-2010.09/include/image.h:365:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 24 /u-boot-2010.09/u-boot-2010.09/include/image.h:366:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 25 /u-boot-2010.09/u-boot-2010.09/include/image.h:367:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 26 /u-boot-2010.09/u-boot-2010.09/include/image.h:368:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 27 /u-boot-2010.09/u-boot-2010.09/include/image.h:369:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 28 /u-boot-2010.09/u-boot-2010.09/include/image.h:370:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 29 /u-boot-2010.09/u-boot-2010.09/include/image.h:371:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 30 /u-boot-2010.09/u-boot-2010.09/include/image.h:378:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’ 31 /u-boot-2010.09/u-boot-2010.09/include/image.h:379:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’ 32 /u-boot-2010.09/u-boot-2010.09/include/image.h:380:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’ 33 /u-boot-2010.09/u-boot-2010.09/include/image.h:381:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’ 34 /u-boot-2010.09/u-boot-2010.09/include/image.h:383:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘char’ 35 /u-boot-2010.09/u-boot-2010.09/include/image.h:388:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 36 /u-boot-2010.09/u-boot-2010.09/include/image.h:404:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ulong’ 37 /u-boot-2010.09/u-boot-2010.09/include/image.h:409:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’ 38 /u-boot-2010.09/u-boot-2010.09/include/image.h:413:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ulong’ 39 /u-boot-2010.09/u-boot-2010.09/include/image.h:423:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 40 /u-boot-2010.09/u-boot-2010.09/include/image.h:424:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 41 /u-boot-2010.09/u-boot-2010.09/include/image.h:425:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 42 /u-boot-2010.09/u-boot-2010.09/include/image.h:426:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 43 /u-boot-2010.09/u-boot-2010.09/include/image.h:427:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 44 /u-boot-2010.09/u-boot-2010.09/include/image.h:428:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 45 /u-boot-2010.09/u-boot-2010.09/include/image.h:429:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 46 /u-boot-2010.09/u-boot-2010.09/include/image.h:436:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 47 /u-boot-2010.09/u-boot-2010.09/include/image.h:437:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 48 /u-boot-2010.09/u-boot-2010.09/include/image.h:438:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 49 /u-boot-2010.09/u-boot-2010.09/include/image.h:439:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 50 /u-boot-2010.09/u-boot-2010.09/include/image.h:441:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ 51 /u-boot-2010.09/u-boot-2010.09/include/image.h:455:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 52 /u-boot-2010.09/u-boot-2010.09/include/image.h:459:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 53 /u-boot-2010.09/u-boot-2010.09/include/image.h:463:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 54 /u-boot-2010.09/u-boot-2010.09/include/image.h:467:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 55 /u-boot-2010.09/u-boot-2010.09/include/image.h:545:8: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 56 /u-boot-2010.09/u-boot-2010.09/include/image.h:547:8: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’ 57 /u-boot-2010.09/u-boot-2010.09/include/image.h:561:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ulong’ 58 /u-boot-2010.09/u-boot-2010.09/include/image.h:573:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ulong’ 59 /u-boot-2010.09/u-boot-2010.09/include/image.h:586:15: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘const’ 60 default_image.c: 在函数‘image_set_header’中: 61 default_image.c:113:2: 警告:隐式声明函数‘image_set_magic’ 62 default_image.c:114:2: 警告:隐式声明函数‘image_set_time’ 63 default_image.c:115:2: 警告:隐式声明函数‘image_set_size’ 64 default_image.c:116:2: 警告:隐式声明函数‘image_set_load’ 65 default_image.c:117:2: 警告:隐式声明函数‘image_set_ep’ 66 default_image.c:118:2: 警告:隐式声明函数‘image_set_dcrc’ 67 default_image.c:119:2: 警告:隐式声明函数‘image_set_os’ 68 default_image.c:120:2: 警告:隐式声明函数‘image_set_arch’ 69 default_image.c:121:2: 警告:隐式声明函数‘image_set_type’ 70 default_image.c:122:2: 警告:隐式声明函数‘image_set_comp’ 71 default_image.c:124:2: 警告:隐式声明函数‘image_set_name’ 72 default_image.c:129:2: 警告:隐式声明函数‘image_set_hcrc’ 73 /u-boot-2010.09/u-boot-2010.09/rules.mk:43: recipe for target `default_image.o‘ failed 74 make[1]: *** [default_image.o] Error 1 75 make[1]: 离开目录“/u-boot-2010.09/u-boot-2010.09/tools” 76 Makefile:378: recipe for target `tools‘ failed 77 make: *** [tools] Error 2
1、首先,需要了解gcc的错误告警信息。
1)错误位置:文件名:行号:列号。【注意:gcc工具的告警信息不是很友好,显示的错误位置可能不是真实的位置】
2)引用关系:错误提示中,第2~4行,表示头文件的引用关系(一层一层的引用)。
default_image.c 第30行 -- mkimage.h 第35行 -- fdt_host.h第25行-- libfdt.h
3)主要的错误类型: 错误:expected ‘=‘, ‘,‘, ‘;‘, ‘asm‘ or ‘__attribute__‘ before
初步搜索,发现该问题和 头文件中 inline 关键字相关。
1 GCC implements three different semantics of declaring a function inline. One is available with ‘-std=gnu89’ or ‘-fgnu89-inline’ or when gnu_inline attribute is present on all inline declarations, another when ‘-std=c99’ or ‘-std=gnu99’ (without ‘-fgnu89-inline’), and the third is used when compiling C++. 2 To declare a function inline, use the inline keyword in its declaration, like this: 3 static inline int inc (int *a) 4 { 5 (*a)++; 6 } 7 If you are writing a header file to be included in ISO C89 programs, write __inline__ instead of inline
2、从错误信息可以看到,gcc包含了参数 -ansi。
而 -ansi,对于gcc工具就等于 -std=c89。
在libfdt.h文件中,第162行如下
static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
告警信息为第15列,void是错误的信息,gcc认为缺少 ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
3、找到-ansi的位置并修改。
U-boot 编译工具相关的配置,都在主文件夹 config.mk文件中,
1 ifeq ($(HOSTOS),cygwin) 2 HOSTCFLAGS += -ansi 3 endif
从配置中可以,u-boot认为在cygwin下,需要增加-ansi的编译选型。
但实际,由于u-boot-2010.09文件是根据C99规范编写的,应该删除该信息。
4、gcc工具编译错误的问题得到解决。
1 gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -idirafter /u-boot-2010.09/u-boot-2010.09/include
-idirafter /u-boot-2010.09/u-boot-2010.09/include2 -idirafter /u-boot-2010.09/u-boot-2010.09/include
-I /u-boot-2010.09/u-boot-2010.09/lib/libfdt -I /u-boot-2010.09/u-boot-2010.09/tools
-DTEXT_BASE=0x11080000 -DUSE_HOSTCC -D__KERNEL_STRICT_NAMES -pedantic -o img2srec.o img2srec.c -c 2 gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -idirafter /u-boot-2010.09/u-boot-2010.09/include
-idirafter /u-boot-2010.09/u-boot-2010.09/include2 -idirafter /u-boot-2010.09/u-boot-2010.09/include
-I /u-boot-2010.09/u-boot-2010.09/lib/libfdt -I /u-boot-2010.09/u-boot-2010.09/tools
-DTEXT_BASE=0x11080000 -DUSE_HOSTCC -D__KERNEL_STRICT_NAMES -pedantic -o img2srec img2srec.o 3 strip img2srec
可以看到正常生成了 img2srec.o
5、后记
C语言标准比较多,gcc支持的也比较多,相关关键字有:
gcc-4.5支持的C语言标准
1 -ansi In C mode, this is equivalent to ‘-std=c89’. In C++ mode, it is equivalent to ‘-std=c++98’. 2 -std= Determine the language standard. A value for this option must be provided; possible values are 3 ‘c89’ 4 ‘iso9899:1990’ 5 Support all ISO C90 programs (certain GNU extensions that conflict 6 with ISO C90 are disabled). Same as ‘-ansi’ for C code. 7 ‘iso9899:199409’ 8 ISO C90 as modified in amendment 1. 9 ‘c99’ 10 ‘c9x’ 11 ‘iso9899:1999’ 12 ‘iso9899:199x’ 13 ISO C99. Note that this standard is not yet fully supported; 14 see http://gcc.gnu.org/gcc-4.3/c99status.html for more information. 15 The names ‘c9x’ and ‘iso9899:199x’ are deprecated. 16 ‘gnu89’ GNU dialect of ISO C90 (including some C99 features). This is the default for C code. 17 ‘gnu99’ 18 ‘gnu9x’ GNU dialect of ISO C99. When ISO C99 is fully implemented in GCC, this will become the default.
The name ‘gnu9x’ is deprecated. 19 ‘c++98’ The 1998 ISO C++ standard plus amendments. Same as ‘-ansi’ for C++ code. 20 ‘gnu++98’ GNU dialect of ‘-std=c++98’. This is the default for C++ code. 21 ‘c++0x’ The working draft of the upcoming ISO C++0x standard. This option enables experimental features
that are likely to be included in C++0x. The working draft is constantly changing,
and any feature that is enabled by this flag may be removed from future versions of GCC
if it is not part of the C++0x standard. 22 ‘gnu++0x’ GNU dialect of ‘-std=c++0x’. This option enables experimental features
that may be removed in future versions of GCC.
===【未完待续】===