错误信息:
/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