这几天keil出了些错误,想想得整理整理下这些错误的原因和解决方案,呵呵,时间长了自然就不会再错了,也能让自己对code的整个框架更为熟悉。

博文中的错误都是我遇到过的,每一个错误都是在网上查到原因和解决方案以及通过自己验证后才发表上来的,因此这篇博文质量第一,数量不定

 

1.warning c316:unterminated conditionals

该错误是说,你的*.c文件有一个凌乱的条件编译或预编译。因为C语言中有时自己做头文件,头文件中的预编译或宏定义,那么条件编译就避免不了。那写条件编译时,可能有忘写一个基本的语句。比如说,你用了条件编译#ifndef而忘记写#endif。因为他们本来就是配套的。有前者必有后者。不能丢掉其中任何一个。就像你写C语句,你不会写了 int i   而不能忘记写 " ; " 。总之,出现上述问题。先看看整个C文件中是否出现上述错误。或整个工程中自己做的头文件中。

2.warning L16:uncalled segment

keil help document:

 

This warning occurs when functions, which were not previously called, are contained in a program (e.g., for test purposes). The function specified is excluded from the overlay process in this case. It is possible that the program then occupies more memory as during a call of the specified segment.

定义了未使用的函数或者一些类型的变量,虽然不影响程序运行,但会占用mcu的rom,而且这也不是良好的编程习惯。

鄙视在options for target里设置disable warning L16的人,治标不治本。

解决方案:1.直接删掉没用的code或者注释掉

          2.若是在自定义的头文件里出现这种错误,那可以用条件编译解决。(我还没学会条件编译呢,一会儿再研究研究,呵呵)

例:*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
    SEGMENT: ?CO?CJM

注:如果是定义了未调用的函数,则在警告栏里面给出的名字是?PR?前缀的函数名;
如果是定义了未调用的code属性数组,则警告栏里给出的消息是?CO?前缀的主程序文件名。

 

3_unresolved external symbol

Warning L1

Summary
*** Warning L1

Unresolved External Symbol
Symbol: symbol-name
Module: filename (module-name)

Description

The symbol symbol-name (which represents a variable or function) was referenced by module-name (in the filename source file) but the linker could not find a public definition of the symbol in any of the object files or library files.

Cause

This problem could be caused by any of a number of problems:

  • The function or variable name may be wrong.
  • The function or variable may not be declared.
  • The function or variable may not be public.
  • The necessary library may not be included.
Resolution

Use the source browser in the µVision IDE to search for the definition of the symbol. If the problem is with a standard library routine make sure that the library is included in the linkage (this may be the problem if no C files are included in the project).

这是keil官方解释,一般都是没有把相应的文件加入工程里。