error: field struct timespec trigger_tstamp has incomplete type

编译时遇到“has incomplete type” 的Error ,这种error 是在引用struct timespec 时还没有定义,因此,需要加入struct timespec 的定义。

In file included from compress.c:74:
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:458:18: error: field 鈥[01mtrigger_tstamp鈥has incomplete type
  458 |  struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */
      |                  ^~~~~~~~~~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:459:18: error: field 鈥[01mtstamp鈥has incomplete type
  459 |  struct timespec tstamp;  /* reference timestamp */
      |                  ^~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:468:18: error: field 鈥[01maudio_tstamp鈥has incomplete type
  468 |  struct timespec audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */
      |                  ^~~~~~~~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:469:18: error: field 鈥[01mdriver_tstamp鈥has incomplete type
  469 |  struct timespec driver_tstamp; /* useful in case reference system tstamp is reported with delay */
      |                  ^~~~~~~~~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:471:37: error: invalid application of 鈥[01msizeof鈥to incomplete type 鈥[01mstruct timespec鈥
  471 |  unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */
      |                                     ^~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:478:18: error: field 鈥[01mtstamp鈥has incomplete type
  478 |  struct timespec tstamp;  /* Timestamp */
      |                  ^~~~~~
/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h:480:18: error: field 鈥[01maudio_tstamp鈥has incomplete type
  480 |  struct timespec audio_tstamp; /* from sample counter or wall clock */

参考这个链接,讲的比较清楚。

c - GCC with -std=c99 complains about not knowing struct timespec - Stack Overflow

struct timespec 在POSIX 中定义,我原始的makefile 为

CFLAGS += -std=c99 -Wall -Wextra -Wunused -DVERSION=\"${VER}\" -I./include

c99 标准没有定义struct timespec,因此会报error.

根据上述链接,需要Enable POSIX.

方式有3种,

1)CFLAGS 中,c99 改为gnu99, 验证可成功编译。

2)Adding -D_GNU_SOURCE to your CFLAGS will also work.验证可成功编译。

3)source code 中Enable Macro, 验证也可行。因为这种方法需要改source code ,而且我的报错是在/opt/compiler_tool/arm/gcc-linaro-9.2.1-20220411-x86_64_arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sound/asound.h, 因此每个include asound.h 的地方,都需要加下面的这段code,这种方法不是很方便。

#if !defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
#if defined(__cplusplus)
#define _XOPEN_SOURCE 700   /* SUS v4, POSIX 1003.1 2008/13 (POSIX 2008/13) */
#elif __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 700   /* SUS v4, POSIX 1003.1 2008/13 (POSIX 2008/13) */
#else
#define _XOPEN_SOURCE 500   /* SUS v2, POSIX 1003.1 1997 */
#endif /* __STDC_VERSION__ */
#endif /* !_XOPEN_SOURCE && !_POSIX_C_SOURCE */

针对这种方法,也可以在  CFLAGS 加固定的宏定义,比如-D_XOPEN_SOURCE=700

CFLAGS += -std=c99 -D_XOPEN_SOURCE=700 -Wall -Wextra -Wunused -DVERSION=\"${VER}\" -I./include

这种修改方法,可以成功编译。

更多编译宏,可以参考GNU manual description.

Feature Test Macros (The GNU C Library)icon-default.png?t=N4P3https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html#index-_005fPOSIX_005fC_005fSOURCE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值