std::thread run time error "Enable multithreading to use std::thread: Operation not permitted"

  • I am trying to port a program that was running without any problem when the environment set up was
    Ubuntu 12.0
    QTCreator Version - 2.4.1
    QT - 4.8.0
    gcc - 4.6.3 to a new environment

    Ubuntu 14.04
    QTCreator Version - 3.0.1
    QT - 5.2.1
    gcc - 4.8

    Unfortunately I end up seeing a runtime error "terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread:Operation not permitted"

    As per my understanding this seems to be an issue with compiler compatibility. Either I miss some options during compilations or a bug from compiler.

    How to get his fixed? Any help is greatly appreciated.

  • Hi, and welcome to the Qt forum!
    That's a bug in the Ubuntu gcc package, see here. As a workaround it's suggested to add the following compiler flags: -Wl,--no-as-needed

  • @Wieland Thank you very much for the reply. I have tried that and still see the same issue. Please find my compile output. Any issue with the compiler options?

    ++ -c -pipe -std=c++11 -pthread -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/i386-linux-gnu/qt5/mkspecs/linux-g++ -I../SimulatorSiteControl -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -I. -o map.o ../SimulatorSiteControl/Map/map.cpp
    g++ -Wl,-O1 -o SimulatorSimulatorSiteControl main.o simulator.o map.o cbmapnotification.o notifymapactivestate.o -lQt5Gui -L/usr/lib/i386-linux-gnu -lQt5Core -lGL -lpthread

  • Are you using qmake for this? How did you add the suggested compiler options?

  • Qt Champions 2017

    It can't be qmake, as in my experience qmake generates the make compile lines with -fPIC and doesn't rely on the "position independent executable" option in g++. Also switching from one optimization level to the other between compiler and linker is odd ...

  • @Wieland, @kshegunov ,

    Its qmake as per my understanding. I tried adding QMAKE_CXXFLAGS += -Wl,--no-as-needed and CONFIG += -Wl,--no-as-needed in .pro file. Both options generate the same output.
    Please find compiler output
    11:22:41: Running steps for project SimulatorSimulatorSiteControl...
    11:22:41: Starting: "/usr/lib/i386-linux-gnu/qt5/bin/qmake" /home/dhanesh/Simulator/SimulatorSiteControl/ -r -spec linux-g++ CONFIG+=declarative_debug CONFIG+=qml_debug
    11:22:41: The process "/usr/lib/i386-linux-gnu/qt5/bin/qmake" exited normally.
    11:22:41: Starting: "/usr/bin/make"

    In generated makefile I see LFLAGS = -Wl,-O1

    I still miss something and just not sure what it is.

  • Qt Champions 2017

    Do you mind sharing the project file you run through qmake?

  • QMAKE_CXXFLAGS += -std=c++11 -pthread
    QMAKE_CXXFLAGS += -Wl,--no-as-needed
    TEMPLATE = app
    CONFIG += -console
    CONFIG += -qt

    SOURCES += main.cpp

    HEADERS +=

  • Qt Champions 2017


    Why those lines?

    CONFIG += -console
    CONFIG += -qt

    Additionally, c++11 can be passed as config, and there's in general no need to mess with the compiler/linker flags directly. Is your application a Qt GUI or do you have a console application; do you use Qt in it, or you just use qmake and Creator as build environment?

    If you don't use Qt at all, you can try something along the lines (for a console app):

    QT -= core gui  #< No Qt libraries
    TEMPLATE = app
    CONFIG += c++11 console #< Console application with C++11 enabled (if the compiler supports it)
    CONFIG -= app_bundle
    LIBS += -lpthread   #< Although, I think this is not necessary. I think qmake links that by default
    SOURCES += ...
    HEADERS += ...

  • Thank You All. Finally I got it working. The way I passed compiler option was wrong. Once again thank you very much for the support and guidance

Log in to reply

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