C program gcc compilation common errors and solutions

1. Introduction

This article is mainly to sort out the solutions to common errors in the c program compilation process, so that everyone can solve the problem in time.

2. Common errors and solutions

1. Array definition error

../../Libs/cmd/cmd_reboot.c:29:69: error: excess elements in array initializer [-Werror]
unsigned long pmu_arr[3] ={ 0x082000a3, 0xf72000a2, 0x7f2190a2, 0xff };
                                                                    ^~~~
1 error generated.
common.mk:322: recipe for target 'obj_dir/cmd_reboot.o' failed

Define an array a[n], indicating that the array has n elements, then the largest subscript of the element in this array is n–1; and the element a[i] represents the i+1th element in the array a, and the array is modified as It can be expressed as follows.

unsigned long pmu_arr[] = { 0x082000a3, 0xf72000a2, 0x7f2190a2, 0xff };
unsigned long pmu_arr[4] = { 0x082000a3, 0xf72000a2, 0x7f2190a2, 0xff };

2、Not enough information to produce a SYMDEFs file

"/tmp/aerY4D", line 73 (column 6): Warning: L6312W: Empty Execution region description for region _lu_data
Error: L6388E: ScatterAssert expression (ImageLimit(_guard) <= (0x880010000 + 0x70000 - (0x20 * 0x400))) failed on line 79 : (0x880078180 <= 0x880078000)
Not enough information to produce a SYMDEFs file.
Finished: 1 information, 1 warning and 1 error messages.

Solution:
This kind of error is generally the memory space size of each project specified by a .sct file in each project directory. You can modify the memory value as needed, but be careful not to overlap with other spaces. The specific definition example is as follows .
insert image description hereinsert image description here

3. The file is garbled <U+0000>

11-19 10:42:20.779 W   ../../Share/Lib/InfoPage.c:1161:7: error: null character ignored [-Werror,-Wnull-character]
11-19 10:42:20.779 W   <U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>

This method is mainly caused by cross-modifying codes under linux and windows. The default encoding of Windows is GBK, and the default encoding of Linux is UTF-8.
Solution: Set the program encoding method.
Take source insight as an example. A single file is garbled
. problem solved! ! !
Method 2: You can directly delete the extra blank lines at the end of the file.

Solution to all garbled files:
[Options] > [Preferences] > File tab in the menu bar, the bottom "Default encoding": change to System Default (Windows ANSI) or Chinese Simplified (GB2312) CP:936, click OK, problem solved! ! !

4. Undefined or undeclared error reporting

If you only declare the function without defining the function (the specific implementation part of the function), then an error will be reported directly:

Error: L6218E: Undefined symbol function“XXX” (referred from main.o)

If there is no declaration, but the function is already defined, only a warning will appear:

Warning: #223-D: function “XXX” declared implicitly!

About warning Warning: Implicit declaration of function “xxx” is invalid in C99! , indicating that the function has been defined, there is a problem with the declaration of the function, check the following points:
1. The declaration of the function is placed in the header file (H file);
2. The function definition is in the source file (C file);
3. Is the name of the function correct? Consistent (capitalization should be consistent);
4. The header file declaring the called function has been included (#include);
5. The sequence of function declarations (the called function declaration is placed before the declaration of the calling function).

5. Chinese is mistakenly added to the code

  if (r_scratch->s[16] ==PM_SP_FLAG ? TRUE : FALSE<U+FF09>
//出现<U+FF09>报错删除相应报错点代码即可。

3. Other related links

1. Detailed summary of commonly used functions in C language

2. Summary of using pointers and arrays as function parameters in C language

3. Summary of byte count and printing format of common data types in C language

4. Summary of printing debugging information added in C language, Makefile and shell

5. Summary of volatile keywords in c language

Guess you like

Origin blog.csdn.net/Luckiers/article/details/127409391