Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add -pthread compiler option in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to add -pthread compiler option in Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BadPistol97
    wrote on 14 May 2019, 16:50 last edited by BadPistol97
    #1

    OS: Windows 7
    Compiler: Qt 5.11.2 MinGW 32-bit
    Program compiled in debug.

    I am using Botan library recently to create a ECDSA_PrivateKey object. But the compiler is complaining about the undefined reference to 'std::thread::_State::~_State()' in rsa.cpp and thread_pool.cpp, both from botan.

    0_1557852309035_Capture.PNG

    This is how I added the botan library:
    0_1557851716346_Capture.PNG

    Code:

    #include <QCoreApplication>
    #include <botan/pubkey.h>
    #include <botan/ec_group.h>
    #include <botan/ecdsa.h>
    #include <iostream>
    #include <botan/pkcs8.h>
    #include <string.h>
    
    using std::cout;
    using std::endl;
    
    
    int main(int argc, char *argv[])
    {
    
        QCoreApplication a(argc, argv);
    
        std::unique_ptr<Botan::RandomNumberGenerator> random(new Botan::System_RNG);
    
        std::unique_ptr<Botan::EC_Group> group(new Botan::EC_Group("secp256r1"));
    
        std::unique_ptr<Botan::ECDSA_PrivateKey> aKey(new Botan::ECDSA_PrivateKey(*random,*group));
    
        std::string encoded;
    
        // this line caused the error.
        encoded = Botan::PKCS8::PEM_encode(*aKey);
    
        return a.exec();
    }
    
    

    According to randombit: "Botan uses threads internally, you may have to add -pthread to gcc command line."

    Now I know -pthread is a compiler option but when I try to use the option in cmd like: qmake -pthread, it says ***unknown option -pthread

    Is -pthread really an option in Qt? And CONFIG += thread in .pro doesn't work. Need some help here, thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 May 2019, 19:25 last edited by aha_1980
      #2

      Hi,

      Add LIBS += -lpthread to your .pro file.

      [Edit aha_1980: Fix typo]

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • B Offline
        B Offline
        BadPistol97
        wrote on 16 May 2019, 15:31 last edited by
        #3

        It doesn't work, the compiler is still complaining the same undefined reference.

        .pro file:

        QT -= gui
        
        CONFIG += c++11 console
        CONFIG -= app_bundle
        
        
        # The following define makes your compiler emit warnings if you use
        # any feature of Qt which as been marked deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        # You can also make your code fail to compile if you use deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
                main.cpp
        
        QMAKE_LFLAGS +=-fstack-protector
        
        LIBS +=-lpthread
        
        
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        unix|win32: LIBS += -L$$PWD/../../../Enzo/Library/botan-master/botan-master/ -lbotan-2
        
        INCLUDEPATH += $$PWD/../../../Enzo/Library/botan-master/botan-master/build/include
        DEPENDPATH += $$PWD/../../../Enzo/Library/botan-master/botan-master/build/include
        
        win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../../Enzo/Library/botan-master/botan-master/botan-2.lib
        else:unix|win32-g++: PRE_TARGETDEPS += $$PWD/../../../Enzo/Library/botan-master/botan-master/libbotan-2.a
        
        
        1 Reply Last reply
        0
        • B Offline
          B Offline
          BadPistol97
          wrote on 16 May 2019, 15:33 last edited by
          #4

          I built the Botan library using my own MinGW 8.1.0 instead of Qt's MinGW, does that matter?

          A 1 Reply Last reply 16 May 2019, 18:32
          0
          • B BadPistol97
            16 May 2019, 15:33

            I built the Botan library using my own MinGW 8.1.0 instead of Qt's MinGW, does that matter?

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 16 May 2019, 18:32 last edited by aha_1980
            #5

            @BadPistol97 said in How to add -pthread compiler option in Qt?:

            I built the Botan library using my own MinGW 8.1.0 instead of Qt's MinGW, does that matter?

            Why don't you just try building it with the same version?

            According to randombit: "Botan uses threads internally, you may have to add -pthread to gcc command line."

            I think you can add this by QMAKE_CXXFLAGS += -pthread (QMAKE_CLFLAGS for C files resp.) to your .pro file.

            However, I think you're just not linking to the correct library. Find out which one is exporting exactly the symbols you're missing.

            At least, this line: LIBS +=-lpthread just links against libpthread.so. Where do you link against botan?

            Regards

            Qt has to stay free or it will die.

            B 1 Reply Last reply 20 May 2019, 07:42
            2
            • A aha_1980
              16 May 2019, 18:32

              @BadPistol97 said in How to add -pthread compiler option in Qt?:

              I built the Botan library using my own MinGW 8.1.0 instead of Qt's MinGW, does that matter?

              Why don't you just try building it with the same version?

              According to randombit: "Botan uses threads internally, you may have to add -pthread to gcc command line."

              I think you can add this by QMAKE_CXXFLAGS += -pthread (QMAKE_CLFLAGS for C files resp.) to your .pro file.

              However, I think you're just not linking to the correct library. Find out which one is exporting exactly the symbols you're missing.

              At least, this line: LIBS +=-lpthread just links against libpthread.so. Where do you link against botan?

              Regards

              B Offline
              B Offline
              BadPistol97
              wrote on 20 May 2019, 07:42 last edited by
              #6

              @aha_1980 I have rebuilt the botan library using Qt's own MinGW compiler and now it works.

              But the botan-test stuck when testing tls:
              0_1558338073284_Capture.PNG

              A 1 Reply Last reply 20 May 2019, 08:20
              0
              • B BadPistol97
                20 May 2019, 07:42

                @aha_1980 I have rebuilt the botan library using Qt's own MinGW compiler and now it works.

                But the botan-test stuck when testing tls:
                0_1558338073284_Capture.PNG

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 20 May 2019, 08:20 last edited by
                #7

                @BadPistol97 I'd say run it in a debugger, and when it crashes send the stack trace to the botan developers.

                They might be best telling you what goes wrong and if it is harmful.

                Regards

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  BadPistol97
                  wrote on 20 May 2019, 16:39 last edited by
                  #8

                  Thank you very much.

                  1 Reply Last reply
                  1

                  2/8

                  14 May 2019, 19:25

                  topic:navigator.unread, 6
                  • Login

                  • Login or register to search.
                  2 out of 8
                  • First post
                    2/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved