User avatar
mad-hatter
Posts: 419
Joined: Sun Feb 26, 2012 2:58 pm
Location: By the UK seaside

C++/Qt4 - Compiling error after update/upgrade [Solved]

Sun Aug 31, 2014 2:24 pm

Hello,

This maybe coincidence or me, being stupid.
I ran a full update today:-

Code: Select all

apt-get update && apt-get upgrade && apt-get dist-upgrade && apt-get install raspberrypi* && rpi-update
First thing I noticed was the cursor had changed, shows 'waiting/clock' on long operations, never noticed it doing so before.
My problem is that a program that previously compiled OK now does not.
Shown below is the code that refers to time.
Any body got any suggestions?

Regards

Code: Select all

compile output:-

:-1: error: common.o: undefined reference to symbol 'clock_gettime@@GLIBC_2.4'

:-1: error: error adding symbols: DSO missing from command line
/lib/arm-linux-gnueabihf/librt.so.1

Code: Select all

class cr
{
public:
    static void delay(quint32, bool);
    static void nanoDelay(quint32);
};

Code: Select all

#include <QTime>

void cr::delay(quint32 delay, bool type) {
    if (type) usleep(delay); //microseconds
    else {                   //milliseconds
        QTime stopTime = QTime::currentTime().addMSecs(delay);
        while(QTime::currentTime() < stopTime) {
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }
    }
}

void cr::nanoDelay(quint32 delay) { // nanoseconds
    quint32 endNsecs;
    struct timespec time_now;

    clock_gettime(CLOCK_REALTIME, &time_now);
    endNsecs = (quint32)time_now.tv_nsec + delay;

     while (endNsecs > (quint32)time_now.tv_nsec) {
        clock_gettime(CLOCK_REALTIME, &time_now);
    }
}

Code: Select all

dmesg on a fresh reboot:-
[   37.106086] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[   38.438441] bcm2835-cpufreq: switching to governor ondemand
[   38.438475] bcm2835-cpufreq: switching to governor ondemand
[   44.559150] bcm2708_fb_blank blank_mode=1
[   44.571565] bcm2708_fb_blank returns=1 p[1]=0x80000000
[   46.245174] bcm2708_fb_blank blank_mode=0
[   46.254526] bcm2708_fb_blank returns=0 p[1]=0x80000000
[   67.134334] bcm2835_audio_set_ctls:558  Controls set for stream 0
[   69.166222] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
Last edited by mad-hatter on Sun Aug 31, 2014 8:56 pm, edited 1 time in total.

Heater
Posts: 13894
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++/Qt4 - Compiling error after update/upgrade 31-8-2014

Sun Aug 31, 2014 2:51 pm

Memory in C++ is a leaky abstraction .

User avatar
mad-hatter
Posts: 419
Joined: Sun Feb 26, 2012 2:58 pm
Location: By the UK seaside

Re: C++/Qt4 - Compiling error after update/upgrade 31-8-2014

Sun Aug 31, 2014 5:16 pm

Hello Heater,

Thanks for your reply.
What I don't understand is that 2 days ago it compiled OK, I didn't have to add any compile flags.
Since then I've done my update/upgrade etc., I also removed gambas3 and
did an apt-get autoremove, I wonder if the autoremove took those files out.
I did a system search on libudev.*, I know it exits and this is OK.
I did a system search on librt.* and its not in the expected directory.
Can I just copy the files from /lib/arm-linux-gnueabihf/ to /usr/lib/ and run 'ldd' or should I reinstall gambas 3.

Regards

Code: Select all

root@mypi:/# find -name libudev.*
...
./usr/lib/libudev.a
./usr/lib/libudev.so
...

root@mypi:/# find -name librt.*
./lib/arm-linux-gnueabihf/librt.so.1
./usr/lib/arm-linux-gnueabihf/librt.so
./usr/lib/arm-linux-gnueabihf/librt.a

Code: Select all

pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = myProg
TEMPLATE = app

SOURCES += \
    myProg.cpp

HEADERS  += \
    myProg.h

LIBS += \
    -L/usr/lib/ -ludev

User avatar
mad-hatter
Posts: 419
Joined: Sun Feb 26, 2012 2:58 pm
Location: By the UK seaside

Re: C++/Qt4 - Compiling error after update/upgrade 31-8-2014

Sun Aug 31, 2014 7:40 pm

Hello Heater,

OK, I've resolved the problem.
I copied librt.a and librt.so from a backup I had.
Ran 'ldconfig'.
Added to the .pro file.
I don't understand why it compiled before, without the change to the .pro file.

Regards

Code: Select all

pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = myProg
TEMPLATE = app

SOURCES += \
    myProg.cpp

HEADERS  += \
    myProg.h

LIBS += \
    -L/usr/lib/ -ludev \
    -L/usr/lib/ -lrt

Return to “C/C++”