为什么我在C中的枚举中出现“错误:错误指令”?

时间:2016-06-14 15:31:53

标签: c enums compiler-errors arm cross-compiling

这很奇怪,对我没有任何意义。我在.h文件中添加了以下枚举:u-boot:

typedef enum LP5521_Patterns_Tag
{
  LP5521_EB_ALL_GOOD,
  LP5521_EB_CLEAR_ALL,
  LP5521_EB_CONNECTED_TO_INTERNET,
  LP5521_EB_ENERGY_BRIDGE_FOUND,
  LP5521_EB_NO_SIGNAL,
  LP5521_EB_PLUGGED_IN,
  LP5521_EB_POOR_CONNECTION,
  LP5521_EB_SERACH_WIFI,
  LP5521_SET_COLOR,
  LP5521_SET_CURRENT,
  LP5521_SET_COLOR_CURRENT,
  LP5521_PATTERNS_TOTAL
}LP5521_Patterns_T;

但是当我尝试编译它时,我得到以下错误:

include/configs/lp5521.h: Assembler messages:
include/configs/lp5521.h:7: Error: bad instruction `typedef enum LP5521_Patterns_Tag'
include/configs/lp5521.h:8: Error: junk at end of line, first unrecognized character is `{'
include/configs/lp5521.h:9: Error: bad instruction `lp5521_eb_all_good,'
include/configs/lp5521.h:10: Error: bad instruction `lp5521_eb_clear_all,'
include/configs/lp5521.h:11: Error: bad instruction `lp5521_eb_connected_to_internet,'
include/configs/lp5521.h:12: Error: bad instruction `lp5521_eb_energy_bridge_found,'
include/configs/lp5521.h:13: Error: bad instruction `lp5521_eb_no_signal,'
include/configs/lp5521.h:14: Error: bad instruction `lp5521_eb_plugged_in,'
include/configs/lp5521.h:15: Error: bad instruction `lp5521_eb_poor_connection,'
include/configs/lp5521.h:16: Error: bad instruction `lp5521_eb_serach_wifi,'
include/configs/lp5521.h:17: Error: bad instruction `lp5521_set_color,'
include/configs/lp5521.h:18: Error: bad instruction `lp5521_set_current,'
include/configs/lp5521.h:19: Error: bad instruction `lp5521_set_color_current,'
include/configs/lp5521.h:20: Error: bad instruction `lp5521_patterns_total'
include/configs/lp5521.h:21: Error: junk at end of line, first unrecognized character is `}'

我注意到它在顶部显示汇编信息,但我也不明白。我已添加的.c文件包含一堆typedef枚举,我没有收到任何错误。

有人可以帮我弄清楚这里发生了什么吗?

我不知道这是否有帮助,但我正在为u-boot添加一些代码并为imx6进行交叉编译。

谢谢!

2 个答案:

答案 0 :(得分:0)

U-boot包含许多CPP预处理的汇编文件(即.S而不是.s);电路板配置标题可能只包含在所有(C文件,汇编文件,链接描述文件)中,因为它通常不仅定义选项,还定义特定于电路板的物理地址等。

除了#defined符号之外的其他任何东西都要求麻烦。

答案 1 :(得分:0)

像这样包装这个枚举:

  #if !defined(__ASSEMBLER__) 

  typedef enum LP5521_Patterns_Tag
  {
  LP5521_EB_ALL_GOOD,
  LP5521_EB_CLEAR_ALL,
  LP5521_EB_CONNECTED_TO_INTERNET,
  LP5521_EB_ENERGY_BRIDGE_FOUND,
  LP5521_EB_NO_SIGNAL,
  LP5521_EB_PLUGGED_IN,
  LP5521_EB_POOR_CONNECTION,
  LP5521_EB_SERACH_WIFI,
  LP5521_SET_COLOR,
  LP5521_SET_CURRENT,
  LP5521_SET_COLOR_CURRENT,
  LP5521_PATTERNS_TOTAL
  }LP5521_Patterns_T;

  #endif

为Assembler定义_ ASSEMBLER _符号,它应该可以工作。