Results 1 to 2 of 2

Thread: Issue with clock_gettime

  1. #1
    Join Date
    Oct 2015
    Posts
    35
    Thanks
    11
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Issue with clock_gettime

    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

    Qt Code:
    1. struct timespec gettime_now;
    To copy to clipboard, switch view to plain text mode 

    Here's the code in mainwindow.cpp

    Qt Code:
    1. clock_gettime(CLOCK_REALTIME, &gettime_now);
    2. fprintf(file1, "%li %i", (gettime_now.tv_sec+(gettime_now.tv_nsec/1000000)
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Issue with clock_gettime

    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:
    Qt Code:
    1. LIBS += -lrt
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. Replies: 3
    Last Post: 27th January 2013, 23:53
  2. MS C++ issue
    By sepehr in forum Installation and Deployment
    Replies: 4
    Last Post: 29th December 2008, 23:45
  3. XML issue
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 13:01
  4. UI issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:41
  5. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.