Hello and thanks in advance for all the problems this platform has solved for me in the past. Unfortunately I've found a problem, which I couldn't solve.
I'm pretty new to cmake and expanded a demo project with a new executable and some library files. I have no problems compiling the demo project. However, my new project needs to be compiled with c99 standard and suddenly, I get errors implementing the timespec struct from time.h. This is also used in the demo project, so I compiled the demo again with c99 and I've got the same problem.
Running this on Ubuntu, using the gcc compiler and cmake version 2.8.7
Hope I've got all necessary details covered. If not, please let me know and thanks in advance for your efforts!
Best regards
Edit#1: Error messages I get:
- >CLOCK_MONOTONIC< not declared (first use in this function)
- field 'tv_nsec' could not be resolved
- field 'tv_sec' could not be resolved
- Symbol 'CLOCK_MONOTONIC' could not be resolved
- Warnings for implicit declaration of functions 'clock_gettime', 'nanosleep', 'timeradd', 'timercmp'
Edit#2: error output with make VERBOSE=1
/usr/bin/gcc -D_XOPEN_SOURCE=600 -I/home/localadmin/Eclipse_Workspace/SOEM_master/soem -I/home/localadmin/Eclipse_Workspace/SOEM_master/osal -I/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux -I/home/localadmin/Eclipse_Workspace/SOEM_master/oshw/linux -std=c99 -o CMakeFiles/soem.dir/osal/linux/osal.c.o -c /home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:60:50: Warning: »struct timezone« declared in parameter list [activated by default]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:60:50: Warning: range of validity includes only this definition or declaration [activated by default]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c: In function »osal_timer_start«:
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:105:4: Warning: Implicit function »timeradd« [-Wimplicit-function-declaration]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c: In function »osal_timer_is_expired«:
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:120:4: Warning: Implicit declaration of function »timercmp« [-Wimplicit-function-declaration]
/home/localadmin/Eclipse_Workspace/SOEM_master/osal/linux/osal.c:120:61: Error: expected expression before »<« token
make[2]: *** [CMakeFiles/soem.dir/osal/linux/osal.c.o] Error 1
make[2]: Leaving directory '/home/localadmin/Eclipse_Workspace/SOEM_master/build'
make[1]: *** [CMakeFiles/soem.dir/all] Error 2
make[1]: Leaving directory '/home/localadmin/Eclipse_Workspace/SOEM_master/build'
make: *** [all] Error 2
This was the output after definining _XOPEN_SOURCE=600, what was suggested in the other thread that got posted below. So the timespec struct is available, but the functions aren't.
Edit #3: minimal, complete and verifiable example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
int main()
{
struct timespec test;
test.tv_sec = 0;
struct timeval start_time;
struct timeval timeout;
struct timeval stop_time;
timeradd(&start_time, &timeout, &stop_time);
return 0;
}
Compiles without problems. If I use gcc mcv_example.c -std=c99 I get:
mcv_example.c: In function 'main':
mcv_example.c:24:18: error: storage size of 'test' isn't known
mcv_example.c:29:2: warning: implicit declaration of function 'timeradd' [-Wimplicit-function-declaration]
Edit#4: The solution for me was using gnu99 instead of c99. Now I can create the UNIX Makefiles with cmake, but still can't create a working Eclipse project.
Since that is a different problem, I guess this case is closed and thank you all for your help and efforts!