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. Trying to build hello world directly with g++
Forum Update on Monday, May 27th 2025

Trying to build hello world directly with g++

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.3k Views
  • 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.
  • A Offline
    A Offline
    Alfredo Palhares
    wrote on last edited by
    #1

    Hello everyone,

    I am new to Qt and would like to build a simple hello world application with just g++ itself.

    I installed Qt 5.4.0 with the Qt installer, edited a main.cpp:

    #include <QApplication>
    #include <QPushButton>
    
    int main(int argc, char **argv)
    {
      QApplication app (argc, argv);
    
      QPushButton button("Hello world !");
      button.show();
    
      return app.exec();
    }
    

    But while building with g++:

    g++ -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/mkspecs/linux-g++ \
      -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtCore \
      -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include \
      -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtWidgets \
      -fPIE main.cpp -o yats
    /tmp/ccdmzDBq.o: In function `main':
    main.cpp:(.text+0x25): undefined reference to `QApplication::QApplication(int&, char**, int)'
    main.cpp:(.text+0x50): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
    main.cpp:(.text+0x68): undefined reference to `QWidget::show()'
    main.cpp:(.text+0x6d): undefined reference to `QApplication::exec()'
    main.cpp:(.text+0x7b): undefined reference to `QPushButton::~QPushButton()'
    main.cpp:(.text+0x87): undefined reference to `QApplication::~QApplication()'
    main.cpp:(.text+0xab): undefined reference to `QPushButton::~QPushButton()'
    main.cpp:(.text+0xbc): undefined reference to `QPushButton::~QPushButton()'
    main.cpp:(.text+0xcd): undefined reference to `QApplication::~QApplication()'
    /tmp/ccdmzDBq.o: In function `QString::QString(char const*)':
    main.cpp:(.text._ZN7QStringC2EPKc[_ZN7QStringC5EPKc]+0x36): undefined reference to `QString::fromAscii_helper(char const*, int)'
    /tmp/ccdmzDBq.o: In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
    main.cpp:(.text._ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1e): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
    

    I know I could use QtCreator, but I would like to learn how to build this way before doing any real work.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You are not linking to any library.

      Even if you don't want to start with Qt Creator. Using qmake on the command line is the standard way to handle Qt projects or if not qmake, there's also cmake or QBS

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

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        You are not linking to any library.

        Even if you don't want to start with Qt Creator. Using qmake on the command line is the standard way to handle Qt projects or if not qmake, there's also cmake or QBS

        A Offline
        A Offline
        Alfredo Palhares
        wrote on last edited by
        #3

        Hello @SGaist

        Thank you, for your reply, I don't really want to use qmake yet.

        I've tried:

         g++ -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/mkspecs/linux-g++ -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtCore -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtGui -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtWidgets -L/home/masterkorp/Qt5.4.0/5.4/gcc_64/lib -lQtCore -lQtGui -fPIC main.cpp -o yats
        /tmp/ccbg9GUi.o: In function `main':
        main.cpp:(.text+0x68): undefined reference to `QWidget::show()'
        /tmp/ccbg9GUi.o: In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
        main.cpp:(.text._ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1e): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
        

        What libraries am I missing ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QtWidgets

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

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            QtWidgets

            A Offline
            A Offline
            Alfredo Palhares
            wrote on last edited by
            #5

            @SGaist said:

            QtWidgets

            Thanks, but I am still hitting unmet references:

            g++ -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/mkspecs/linux-g++ -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtCore -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtGui -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include -I/home/masterkorp/Qt5.4.0/5.4/gcc_64/include/QtWidgets -L/home/masterkorp/Qt5.4.0/5.4/gcc_64/lib -lQt5Core -lQt5Gui -lQt5Widgets -fPIC main.cpp -o yats
            /usr/bin/ld: warning: libicui18n.so.53, needed by /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so, not found (try using -rpath or -rpath-link)
            /usr/bin/ld: warning: libicuuc.so.53, needed by /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so, not found (try using -rpath or -rpath-link)
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_setMillis_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_fromUnicode_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_get_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_inDaylightTime_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_open_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_countAvailable_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_countAliases_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `u_errorName_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openCountryTimeZones_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `u_strToUpper_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getDefaultName_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `uenum_next_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_strcoll_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getMaxCharSize_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getAvailableName_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_open_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getTimeZoneDisplayName_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_toUnicode_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `uenum_close_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_getSortKey_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getAlias_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_close_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_setAttribute_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_close_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openTimeZoneIDEnumeration_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openTimeZones_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getStandardName_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_close_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_compareNames_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_clone_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `u_strToLower_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getDefaultTimeZone_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_open_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_setSubstChars_53'
            /home/masterkorp/Qt5.4.0/5.4/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getDSTSavings_53'
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              libicui18n.so.53 and libicuuc.so.53 can't be found

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

              A 1 Reply Last reply
              1
              • SGaistS SGaist

                libicui18n.so.53 and libicuuc.so.53 can't be found

                A Offline
                A Offline
                Alfredo Palhares
                wrote on last edited by
                #7

                @SGaist said:

                libicui18n

                Should they be installed by the Qt installer ?

                I can now compile using Qt from packages,

                JKSHJ 1 Reply Last reply
                0
                • A Alfredo Palhares

                  @SGaist said:

                  libicui18n

                  Should they be installed by the Qt installer ?

                  I can now compile using Qt from packages,

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @Alfredo-Palhares said:

                  @SGaist said:

                  libicui18n

                  Should they be installed by the Qt installer ?

                  Yes, the Qt installer installs ICU.

                  I suggest you use Qt Creator to build first. Then, study the auto-generated Makefile.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • nulluseN Offline
                    nulluseN Offline
                    nulluse
                    wrote on last edited by
                    #9

                    I am having exact same problem under Fedora Linux today even though I am using the current Qt5.6 fresh from web downloader and QtCreator 4.0.0:

                    g++ -Wl,-z,origin -Wl,-rpath,\$ORIGIN -o MandelbrotQt main.o newform.o fileHelper.o mandelbrot.o netClient.o netServer.o arrayhelper.o stringHelper.o winAPIHelper.o OpenCLHelper.o moc_newform.o moc_fileHelper.o moc_netServer.o moc_netClient.o moc_OpenCLHelper.o   /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so -L/home/user0/Qt/5.6/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Concurrent -lQt5Network -lQt5Core -lGL -lpthread 
                    /usr/bin/ld: warning: libicui18n.so.56, needed by /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so, not found (try using -rpath or -rpath-link)
                    /usr/bin/ld: warning: libicuuc.so.56, needed by /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so, not found (try using -rpath or -rpath-link)
                    /usr/bin/ld: warning: libicudata.so.56, needed by /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so, not found (try using -rpath or -rpath-link)
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_open_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `u_strToLower_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getStandardName_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_compareNames_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_clone_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getAlias_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `uenum_next_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_open_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_setAttribute_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `u_strToUpper_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_setSubstChars_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getTimeZoneDisplayName_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openCountryTimeZones_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_fromUnicode_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_open_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openTimeZones_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_countAliases_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `u_errorName_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_inDaylightTime_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `uenum_close_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getAvailableName_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_close_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_openTimeZoneIDEnumeration_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getDefaultName_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getDSTSavings_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_getDefaultTimeZone_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_toUnicode_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_setMillis_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_strcoll_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_close_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_close_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucol_getSortKey_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_countAvailable_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucnv_getMaxCharSize_56'
                    /home/user0/Qt/5.6/gcc_64/lib/libQt5Core.so: undefined reference to `ucal_get_56'
                    collect2: error: ld returned 1 exit status
                    

                    The libraries are sitting right in /home/user0/Qt/5.6/gcc_64/lib/ but the linker is not using them. Does the installer not configure the tools correctly?

                    1 Reply Last reply
                    0

                    • Login

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