常见编译错误

1. 出现 expected ‘)’ before ‘*’ token

原因是1.  前面的定义在后面 
	  2.  头文件也添加了,可能是定义在某个特定 宏 之中 需要拿出来处理

2. expected specifier-qualifier-list

qualifier 限定符
原因: 包含的头文件 里面 用到了其他头文件的东西
所以要在这个#include 之前 再把那个头文件给包含上

参见百度 expected specifier-qualifier-list before 'size_t'

3. undefined reference to

原因: 没有将文件添加至 makefile 中

4. error: storage class specified for parameter

今天编译时,出现error: storage class specified for parameter问题
在当前行查找时,并没有发现错误,仅仅定义了一个结构体
后向上追溯,发现是新增的头文件中,最后一个函数的声明缺少一个";“ 引起

https://blog.csdn.net/cos_sin_tan/article/details/8439144

5. invalid storage class for function “XXXXX”

后来发现是 “{” “}” 没有匹配

6. expected indentifier or ( before } token

应为标识符或(在}标记之前)

括号不匹配

7. pclint 编译错误 找不到 宏 XXX_LEN_MAX

因为 xxx.h 里面这些宏加了 条件宏 #ifdef __KERNEL__ 
所以用户态编译不过

8. pclint 报 info 776

possible truncation of addition
解决: 用一个临时变量 接 相加的和 然后放到 if 、for 里面操作

9. fileextract 更改为 fileextract 时候出错 cli 不显示

  1. 报错: fileextract/cliplugin/makefile:29: not foud source files of fileextract.cli
  2. 原因: cliplugin makefile 中 生成 fileextract.cli
    但是定制文件 def 中 写成了 cliplugin/libfileextract.cli
    一个是: fileextract,一个是 libfileextract。导致 对不上
  3. 解决: 将 cliplugin makefile 中 生成 fileextract.cli -> libfileextract.cli
  4. 教训: 多看编译错误 不一定搜 error 没有 就没有错误 可能是fault 或者 warning呢
    认真看编译错误

10. warning :discards qualifiers from pointer target

从指针目标中丢弃限定符

一个 warning :discards qualifiers from pointer target type
有关const呢。
定义时是const char * string1;
函数是void fun(char * str)
传进去就有这个warning,
把string1的const去掉 或者调用的时候强制转换fun((char *) string1)

11. ISO C90 forbids mixed declarations and code

  1. 原因 :
    变量定义之前任何一条非变量定义的语句(注意:语句是会带分号的)都会引起这个警告!
  2. 解决方法:
    将非变量的定义移到变量定义之后 即可
    在内核中还需要将 printk的打印放在变量定义之后

12. warning: assignment discards qualifiers from pointer target type

  1. 原因:
    入参 const 参数 函数里面用这个参数当参数调用又不是const 有问题 会报warning

13. error:stray’\274’in program

编写的程序里使用的关键字或变量名不规范而导致错误;
编译器在编译源代码的过程中遇到了不能识别的非法字符,这一个值不在合法的英文字符(0~127)范围内,一般是误输入造成。

肯定是中文符号的问题
https://blog.csdn.net/weixin_44596487/article/details/86579220

14. error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘->’ token

#define 宏中不能添加注释 /* xxxx */

15. dependence placed on C’s operator precedence; operators: ‘+’ and ‘-’

依赖于C的运算符优先级;运算符:“+”和“-”

这个是默认优先级。请使用括号,明确优先级。

这里: 使用()括号 来扩起来 来明确优先级

16. boolean within if always evaluates to true

if中的布尔值总是求值为true

17. Did not expect positive indentation 不希望出现正缩进

缩进的问题 这里是多缩进了一个空格

18. Comparison with extraneous parenthese 与外来括号比较

这里多了一个括号

总结

  1. 很多编译错误:
    2.1 前面的定义在后面
    2.2 头文件添加套路,要添加的头文件里面需要包含其他头文件
    2.3 可能数据结构定义在某个宏中间,需要拿出来,否则编译不过 例如: __kernal

  2. 教训: 多看编译错误 不一定搜 error 没有 就没有错误
    认真看编译错误

  • 6
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值