error: ‘CLOCK_MONOTONIC‘ undeclared (first use in this function)

 错误信息:

/home/xx/test/main.c: In function ‘main’:
/home/xx/test/main.c:37:21: error: storage size of ‘start’ isn’t known
   37 |     struct timespec start, end; //nanoseconds
      |                     ^~~~~
/home/xx/test/main.c:37:28: error: storage size of ‘end’ isn’t known
   37 |     struct timespec start, end; //nanoseconds
      |                            ^~~
/home/xx/test/main.c:43:5: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
   43 |     clock_gettime(CLOCK_MONOTONIC, &start);
      |     ^~~~~~~~~~~~~
/home/xx/test/main.c:43:19: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
   43 |     clock_gettime(CLOCK_MONOTONIC, &start);
      |                   ^~~~~~~~~~~~~~~
/home/xx/test/main.c:43:19: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/WBSM4.dir/build.make:63: CMakeFiles/xx.dir/test/main.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/xx.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

解决方案:

CMakeLists.txt文件中添加编译器: 

add_compile_options(-D_POSIX_C_SOURCE=199309L) 

解决方案来源【版权侵删】:

c++ - error: 'CLOCK_MONOTONIC' undeclared (first use in this function) - Stack Overflow

error: ‘CLOCK_MONOTONIC’ undeclared问题解决_whahu1989的专栏-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值