Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Ubuntu 24.04 and Qt6 and issues with building my first project

Ubuntu 24.04 and Qt6 and issues with building my first project

Scheduled Pinned Locked Moved Solved Installation and Deployment
8 Posts 3 Posters 371 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.
  • N Offline
    N Offline
    Noobish
    wrote on 7 Apr 2025, 12:03 last edited by
    #1

    I'm using ubuntu 24.04 and I think I've managed to install Qt6, but I guess something is still wrong with my setup.
    I'm trying to build a small project but it fails with undefined references OR no such file or directory.

    Here is the first attempt

    #ifndef GAMESERVER_H
    #define GAMESERVER_H
    
    #include <QObject>
    #include <QtNetwork/QTcpServer>
    #include <QtNetwork/QNetworkInterface>
    
    class GameServer : public QObject
    {
        Q_OBJECT
    public:
        explicit GameServer(QObject *parent = nullptr);
    
    protected:
        void initServer();
        QTcpServer *tcpServer = nullptr;
        void exit();
    signals:
    };
    
    #endif // GAMESERVER_H
    

    Which gives

    error: CMakeFiles/fooserver.dir/gameserver.cpp.o: in function GameServer::initServer()': /home/me/fooserver/gameserver.cpp:-1: error: undefined reference to QTcpServer::QTcpServer(QObject*)'

    The gameserver.cpp file contains

    #include "gameserver.h"
    
    #include <QList>
    #include <QString>
    
    GameServer::GameServer(QObject *parent)
        : QObject{parent}
    {
        initServer();
    }
    
    void GameServer::initServer()
    {
        tcpServer = new QTcpServer(this);
    }
    
    void GameServer::exit()
    {
        qDebug()<<"GameServer::exit";
    }
    

    And here is another version where I include just QtNetwork

    #ifndef GAMESERVER_H
    #define GAMESERVER_H
    
    #include <QObject>
    #include <QtNetwork>
    
    class GameServer : public QObject
    {
        Q_OBJECT
    public:
        explicit GameServer(QObject *parent = nullptr);
    
    protected:
        void initServer();
        QTcpServer *tcpServer = nullptr;
        void exit();
    signals:
    };
    
    #endif // GAMESERVER_H
    

    and that gives me

    /home/me/fooserver/gameserver.h:5: error: QNetwork: No such file or directory
    In file included from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/moc_gameserver.cpp:10,
    from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/mocs_compilation.cpp:2:
    /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
    5 | #include <QNetwork>
    | ^~~~~~~~~~

    The whole "kit" thing in qtcreator is kind of new and here is my CMakeLists.txt (which I assume is important)

    cmake_minimum_required(VERSION 3.14)
    
    project(fooserver LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Network)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
    
    add_executable(fooserver
      main.cpp gameserver.cpp gameserver.h
    )
    target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)
    
    include(GNUInstallDirs)
    install(TARGETS fooserver
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    

    So, any hint on how to fix what is broken? Please tell me if you need more information.

    C 2 Replies Last reply 7 Apr 2025, 12:07
    0
    • N Noobish
      7 Apr 2025, 18:21

      @Christian-Ehrlicher said in Ubuntu 24.04 and Qt6 and issues with building my first project:

      @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

      target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)

      You should link against Qt6::Network when you want to use it for this target

      Thank you!!

      I changed to this, and now it worked!

      target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core Qt6::Network)
      
      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 Apr 2025, 19:27 last edited by
      #8

      @Noobish
      If you want to be clean:

      target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core
      Qt${QT_VERSION_MAJOR}::Network)
      

      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
      1
      • N Noobish
        7 Apr 2025, 12:03

        I'm using ubuntu 24.04 and I think I've managed to install Qt6, but I guess something is still wrong with my setup.
        I'm trying to build a small project but it fails with undefined references OR no such file or directory.

        Here is the first attempt

        #ifndef GAMESERVER_H
        #define GAMESERVER_H
        
        #include <QObject>
        #include <QtNetwork/QTcpServer>
        #include <QtNetwork/QNetworkInterface>
        
        class GameServer : public QObject
        {
            Q_OBJECT
        public:
            explicit GameServer(QObject *parent = nullptr);
        
        protected:
            void initServer();
            QTcpServer *tcpServer = nullptr;
            void exit();
        signals:
        };
        
        #endif // GAMESERVER_H
        

        Which gives

        error: CMakeFiles/fooserver.dir/gameserver.cpp.o: in function GameServer::initServer()': /home/me/fooserver/gameserver.cpp:-1: error: undefined reference to QTcpServer::QTcpServer(QObject*)'

        The gameserver.cpp file contains

        #include "gameserver.h"
        
        #include <QList>
        #include <QString>
        
        GameServer::GameServer(QObject *parent)
            : QObject{parent}
        {
            initServer();
        }
        
        void GameServer::initServer()
        {
            tcpServer = new QTcpServer(this);
        }
        
        void GameServer::exit()
        {
            qDebug()<<"GameServer::exit";
        }
        

        And here is another version where I include just QtNetwork

        #ifndef GAMESERVER_H
        #define GAMESERVER_H
        
        #include <QObject>
        #include <QtNetwork>
        
        class GameServer : public QObject
        {
            Q_OBJECT
        public:
            explicit GameServer(QObject *parent = nullptr);
        
        protected:
            void initServer();
            QTcpServer *tcpServer = nullptr;
            void exit();
        signals:
        };
        
        #endif // GAMESERVER_H
        

        and that gives me

        /home/me/fooserver/gameserver.h:5: error: QNetwork: No such file or directory
        In file included from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/moc_gameserver.cpp:10,
        from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/mocs_compilation.cpp:2:
        /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
        5 | #include <QNetwork>
        | ^~~~~~~~~~

        The whole "kit" thing in qtcreator is kind of new and here is my CMakeLists.txt (which I assume is important)

        cmake_minimum_required(VERSION 3.14)
        
        project(fooserver LANGUAGES CXX)
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 17)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Network)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
        
        add_executable(fooserver
          main.cpp gameserver.cpp gameserver.h
        )
        target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)
        
        include(GNUInstallDirs)
        install(TARGETS fooserver
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        )
        
        

        So, any hint on how to fix what is broken? Please tell me if you need more information.

        C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 7 Apr 2025, 12:07 last edited by
        #2

        @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

        /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
        5 | #include <QNetwork>

        This does not match your copied code. QNetwork != QtNetwork

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        N 1 Reply Last reply 7 Apr 2025, 18:08
        3
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Apr 2025, 17:43 last edited by
          #3

          Hi,

          Beside that include issue, you should avoid using module includes. This will bring in everything from the module which will slow building time for nothing.
          Just include what you use (and make use of forward includes).

          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
          0
          • C Christian Ehrlicher
            7 Apr 2025, 12:07

            @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

            /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
            5 | #include <QNetwork>

            This does not match your copied code. QNetwork != QtNetwork

            N Offline
            N Offline
            Noobish
            wrote on 7 Apr 2025, 18:08 last edited by
            #4

            @Christian-Ehrlicher said in Ubuntu 24.04 and Qt6 and issues with building my first project:

            @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

            /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
            5 | #include <QNetwork>

            This does not match your copied code. QNetwork != QtNetwork

            Sorry, I must have lost an t, but the error was the same (with the t)

            error: QtNetwork: No such file or directory

            S 1 Reply Last reply 7 Apr 2025, 18:14
            0
            • N Noobish
              7 Apr 2025, 12:03

              I'm using ubuntu 24.04 and I think I've managed to install Qt6, but I guess something is still wrong with my setup.
              I'm trying to build a small project but it fails with undefined references OR no such file or directory.

              Here is the first attempt

              #ifndef GAMESERVER_H
              #define GAMESERVER_H
              
              #include <QObject>
              #include <QtNetwork/QTcpServer>
              #include <QtNetwork/QNetworkInterface>
              
              class GameServer : public QObject
              {
                  Q_OBJECT
              public:
                  explicit GameServer(QObject *parent = nullptr);
              
              protected:
                  void initServer();
                  QTcpServer *tcpServer = nullptr;
                  void exit();
              signals:
              };
              
              #endif // GAMESERVER_H
              

              Which gives

              error: CMakeFiles/fooserver.dir/gameserver.cpp.o: in function GameServer::initServer()': /home/me/fooserver/gameserver.cpp:-1: error: undefined reference to QTcpServer::QTcpServer(QObject*)'

              The gameserver.cpp file contains

              #include "gameserver.h"
              
              #include <QList>
              #include <QString>
              
              GameServer::GameServer(QObject *parent)
                  : QObject{parent}
              {
                  initServer();
              }
              
              void GameServer::initServer()
              {
                  tcpServer = new QTcpServer(this);
              }
              
              void GameServer::exit()
              {
                  qDebug()<<"GameServer::exit";
              }
              

              And here is another version where I include just QtNetwork

              #ifndef GAMESERVER_H
              #define GAMESERVER_H
              
              #include <QObject>
              #include <QtNetwork>
              
              class GameServer : public QObject
              {
                  Q_OBJECT
              public:
                  explicit GameServer(QObject *parent = nullptr);
              
              protected:
                  void initServer();
                  QTcpServer *tcpServer = nullptr;
                  void exit();
              signals:
              };
              
              #endif // GAMESERVER_H
              

              and that gives me

              /home/me/fooserver/gameserver.h:5: error: QNetwork: No such file or directory
              In file included from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/moc_gameserver.cpp:10,
              from /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/mocs_compilation.cpp:2:
              /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
              5 | #include <QNetwork>
              | ^~~~~~~~~~

              The whole "kit" thing in qtcreator is kind of new and here is my CMakeLists.txt (which I assume is important)

              cmake_minimum_required(VERSION 3.14)
              
              project(fooserver LANGUAGES CXX)
              
              set(CMAKE_AUTOUIC ON)
              set(CMAKE_AUTOMOC ON)
              set(CMAKE_AUTORCC ON)
              
              set(CMAKE_CXX_STANDARD 17)
              set(CMAKE_CXX_STANDARD_REQUIRED ON)
              
              find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Network)
              find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
              
              add_executable(fooserver
                main.cpp gameserver.cpp gameserver.h
              )
              target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)
              
              include(GNUInstallDirs)
              install(TARGETS fooserver
                  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
              )
              
              

              So, any hint on how to fix what is broken? Please tell me if you need more information.

              C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 7 Apr 2025, 18:13 last edited by
              #5

              @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

              target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)

              You should link against Qt6::Network when you want to use it for this target

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              N 1 Reply Last reply 7 Apr 2025, 18:21
              1
              • N Noobish
                7 Apr 2025, 18:08

                @Christian-Ehrlicher said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                /home/me/fooserver/build/Desktop-Debug/fooserver_autogen/EWIEGA46WW/../../../../gameserver.h:5:10: fatal error: QNetwork: No such file or directory
                5 | #include <QNetwork>

                This does not match your copied code. QNetwork != QtNetwork

                Sorry, I must have lost an t, but the error was the same (with the t)

                error: QtNetwork: No such file or directory

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 7 Apr 2025, 18:14 last edited by
                #6

                @Noobish As I suggested, avoid module wide includes.
                Just include what you use, it will be way cleaner in the long run.

                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
                0
                • C Christian Ehrlicher
                  7 Apr 2025, 18:13

                  @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                  target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)

                  You should link against Qt6::Network when you want to use it for this target

                  N Offline
                  N Offline
                  Noobish
                  wrote on 7 Apr 2025, 18:21 last edited by
                  #7

                  @Christian-Ehrlicher said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                  @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                  target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)

                  You should link against Qt6::Network when you want to use it for this target

                  Thank you!!

                  I changed to this, and now it worked!

                  target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core Qt6::Network)
                  
                  S 1 Reply Last reply 7 Apr 2025, 19:27
                  0
                  • N Noobish has marked this topic as solved on 7 Apr 2025, 18:21
                  • N Noobish
                    7 Apr 2025, 18:21

                    @Christian-Ehrlicher said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                    @Noobish said in Ubuntu 24.04 and Qt6 and issues with building my first project:

                    target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core)

                    You should link against Qt6::Network when you want to use it for this target

                    Thank you!!

                    I changed to this, and now it worked!

                    target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core Qt6::Network)
                    
                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 7 Apr 2025, 19:27 last edited by
                    #8

                    @Noobish
                    If you want to be clean:

                    target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core
                    Qt${QT_VERSION_MAJOR}::Network)
                    

                    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
                    1
                    • N Noobish has marked this topic as solved on 7 Apr 2025, 20:21

                    1/8

                    7 Apr 2025, 12:03

                    • Login

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