Raspberry Pi thread - pure virtual function called



  • Hi,
    I'm currently developing a big project under the Raspberry Pi 2 (with Qt Creator).
    Yesterday I was dealing with threads. I got an annoying runtime error.
    So I wrote a little example that shows my problem:

    #include <iostream>
    #include <thread>
    using namespace std;
    
    void hello_function()
    {
        cout << "function hello"<<endl;
    }
    
    int main()
    {
        cout << "1" << endl;
        thread t(hello_function);
        cout << "2" << endl;
        t.join();
        return 0;
    }
    

    output:

    1
    2
    pure virtual method called
    terminate called without an active exception
    

    The error is caused by the thread. After some research I found out that this is a bug in gcc compiler:
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62100
    You'll also find out, that there is recommended to use "-mcpu=cortex-a8" as solution.
    Can anyone explain me where to put this command? Possible to put this in qt's project file?

    At last, some additional information:
    Qt project file:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt
    
    CONFIG   += c++14
    CONFIG += thread
    
    SOURCES += main.cpp
    
    include(deployment.pri)
    qtcAddDeployment()
    

    Some versions:
    Qt Creator 3.2.1 based on Qt 5.3.2 (under Raspberry Pi 2)
    g++ (Raspbian 4.9.2-10) 4.9.2

    /etc/issue:
    Raspbian GNU/Linux 8 \n \l

    /proc/version:
    Linux version 4.1.19-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #858 SMP Tue Mar 15 15:56:00 GMT 2016


  • Lifetime Qt Champion

    Hi,

    You can edit the qmake.conf file in the mkspecs/device/linux-rasp-pi2-g++ folder.



  • Thank you for your help. But that didn't change anything.
    I had a look at the makefile and I'm a bit confused:

    CC            = /usr/bin/gcc
    CXX           = /usr/bin/g++
    DEFINES       = 
    CFLAGS        = -pipe -marm -mfpu=vfp -mtune=arm1176jzf-s -march=armv6zk -mabi=aapcs-linux -mfloat-abi=hard -g -D_REENTRANT -Wall -W -fPIC $(DEFINES)
    CXXFLAGS      = -pipe -marm -mfpu=vfp -mtune=arm1176jzf-s -march=armv6zk -mabi=aapcs-linux -mfloat-abi=hard -g -D_REENTRANT -std=c++1y -Wall -W -fPIC $(DEFINES)
    INCPATH       = -I../threadtest -I. -I/usr/local/qt5/mkspecs/devices/linux-rasp-pi-g++
    QMAKE         = /usr/local/qt5/bin/qmake
    DEL_FILE      = rm -f
    CHK_DIR_EXISTS= test -d
    MKDIR         = mkdir -p
    COPY          = cp -f
    COPY_FILE     = cp -f
    COPY_DIR      = cp -f -R
    INSTALL_FILE  = install -m 644 -p
    INSTALL_PROGRAM = install -m 755 -p
    INSTALL_DIR   = cp -f -R
    DEL_FILE      = rm -f
    SYMLINK       = ln -f -s
    DEL_DIR       = rmdir
    MOVE          = mv -f
    TAR           = tar -cf
    COMPRESS      = gzip -9f
    DISTNAME      = threadtest1.0.0
    DISTDIR = /home/pi/build-threadtest-Qt_5_5_1_qt5-Debug/.tmp/threadtest1.0.0
    LINK          = /usr/bin/g++
    LFLAGS        = -Wl,-rpath-link,/opt/vc/lib -Wl,-rpath-link,/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/lib/arm-linux-gnueabihf -mfloat-abi=hard
    LIBS          = $(SUBLIBS) -lpthread 
    AR            = /usr/bin/ar cqs
    RANLIB        = 
    SED           = sed
    STRIP         = /usr/bin/strip
    ...
    

    Should the compiler flag -march=armv6zk not be something like armv7 ?
    I also tried to add -mcpu=cortex-a8 manually, but the compiler reacts with a warning:
    warning: switch -mcpu=cortex-a8 conflicts with -march=armv6zk switch

    I think I have a bad setting. Obviously the makefile does not fit to the qmake.conf:

    # qmake configuration for the Raspberry Pi 2
    
    include(../common/linux_device_pre.conf)
    
    QMAKE_LFLAGS           += -Wl,-rpath-link,$$[QT_SYSROOT]/opt/vc/lib
    
    QMAKE_LIBDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/lib
    QMAKE_LIBDIR_EGL        = $$QMAKE_LIBDIR_OPENGL_ES2
    
    QMAKE_INCDIR_EGL        = $$[QT_SYSROOT]/opt/vc/include \
                              $$[QT_SYSROOT]/opt/vc/include/interface/vcos/pthreads \
                              $$[QT_SYSROOT]/opt/vc/include/interface/vmcs_host/linux
    QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
    
    QMAKE_LIBS_EGL          = -lEGL -lGLESv2
    QMAKE_CFLAGS += -march=armv7-a -marm -mthumb-interwork -mfpu=neon-vfpv4 -mtune=cortex-a7 -mabi=aapcs-linux
    QMAKE_CXXFLAGS          = $$QMAKE_CFLAGS
    
    DISTRO_OPTS += hard-float
    
    # Preferred eglfs backend
    EGLFS_DEVICE_INTEGRATION = eglfs_brcm
    
    include(../common/linux_arm_device_post.conf)
    
    load(qt_config)
    

    Regards


  • Lifetime Qt Champion

    Is it me or the pasted qmake.conf doesn't contain cortex-a8 ?



  • @SGaist said:

    mkspecs/device/linux-rasp-pi2-g++

    Shouldn't it maybe be mkspecs/device/linux-rasp-pi-g++ (without the 2)?
    In his makefile there is this line:

    INCPATH       = -I../threadtest -I. -I/usr/local/qt5/mkspecs/devices/linux-rasp-pi-g++
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.