Ubuntu 24.04 and Qt6 and issues with building my first project
-
wrote on 7 Apr 2025, 12:03 last edited by
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.
-
@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)
@Noobish
If you want to be clean:target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)
-
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.
@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
-
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). -
@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
wrote on 7 Apr 2025, 18:08 last edited by@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
-
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.
@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
-
@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
@Noobish As I suggested, avoid module wide includes.
Just include what you use, it will be way cleaner in the long run. -
@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
wrote on 7 Apr 2025, 18:21 last edited by@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)
-
-
@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)
@Noobish
If you want to be clean:target_link_libraries(fooserver Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)
-
1/8