PDA

View Full Version : Issue with clock_gettime



rookee
11th December 2015, 15:06
Hello All,

I'm getting the following error while accessing real time clock.

I have the following in my glbs.cpp file. Included both glbs.cpp and glbs.h in mainwindow.cpp headers


struct timespec gettime_now;

Here's the code in mainwindow.cpp



clock_gettime(CLOCK_REALTIME, &gettime_now);
fprintf(file1, "%li %i", (gettime_now.tv_sec+(gettime_now.tv_nsec/1000000)

Here's the error I'm getting:

mainwindow.o: undefined reference to symbol 'clock_gettime@@GLIBC_2.4'
error adding symbols: DSO missing from command line
collect2: Id returned 1 exit status

I looked up online and few of the posts said to add -lrt to the makefile, I added "-lrt" to the end of the line in mainwindow.o. Still I'm getting the same error. One of the posts says "try Project -> Build Options -> Linker Settings ; then add library rt" I didn't understand where to do that. I'm using Qt4.8.1(Qt Creator 2.5). Please help. It's a little urgent. Thanks in advance.

ChrisW67
12th December 2015, 20:17
Read the manual for the function you are trying to use
http://linux.die.net/man/2/clock_gettime
The first few lines tell you how to access it.
If, and only if,you need to link the rt library then add it to the LIBS variable in your PRO file:


LIBS += -lrt


Remove the .CPP file from includes. It an implementation, not a declaration.