Trying to build hello world directly with g++



  • 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.


  • Lifetime Qt Champion

    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



  • 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 ?


  • Lifetime Qt Champion

    QtWidgets



  • @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'
    

  • Lifetime Qt Champion

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



  • @SGaist said:

    libicui18n

    Should they be installed by the Qt installer ?

    I can now compile using Qt from packages,


  • Moderators

    @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.



  • 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?


Log in to reply
 

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