Trying to build a Qt 6 application but getting a Qt 5 application; Qt Creator 19 on Gentoo Linux
-
I'm new to Qt. I selected Qt 6 in my Desktop kit. When I use ldd on the resulting binary I get
libQt5Widgets.so.5 => /usr/lib64/libQt5Widgets.so.5 (0x00007f4decab7000)
libQt5Gui.so.5 => /usr/lib64/libQt5Gui.so.5 (0x00007f4dec486000)
libQt5Core.so.5 => /usr/lib64/libQt5Core.so.5 (0x00007f4debf27000)
among other shared objects. The binary is linked to Qt 5 instead of Qt 6. My application is a normal Qt Widgets Application. There is no difference between Debug and Release in this regard. When I select Qt 5 nothing changes.I assume this is not the normal behavior. How can I get to the root cause of this? Where do I start to dig?
@mgoppelt
Your paths show a Qt5 installed in/usr/lib64, which is presumably supplied by your Linux OS. Quite likely it does not supply a Qt6?So did you fetch and install (a pre-built) Qt6 yourself? Is your kit and build commands not picking that up and compiling/linking against the system's Qt5?
-
Good point. Qt6 is also installed. The shared objects
/usr/lib64/libQt6Core.so.6
/usr/lib64/libQt6Gui.so.6
/usr/lib64/libQt6Widgets.so.6
are available. I'm quite sure that Gentoo builds Qt (both 5 and 6) from the sources. -
Here comes CMakeLists.txt:
cmake_minimum_required(VERSION 3.16) project(Projekt_Muehle VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) #set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include_directories(${PROJECT_SOURCE_DIR}) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(Projekt_Muehle MANUAL_FINALIZATION ${PROJECT_SOURCES} add_args.h add_args.cpp mill_view.h mill_view.cpp mill_model.h mill_model.cpp mill_controller.h mill_controller.cpp player.h player.cpp board.h board.cpp board.ui token.h token.cpp token.ui board_label.h board_label.cpp board_label.ui res.qrc ) # Define target properties for Android with Qt 6 as: # set_property(TARGET Projekt_Muehle APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(Projekt_Muehle SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(Projekt_Muehle ${PROJECT_SOURCES} add_args.cpp add_args.h board.cpp board.h board.ui board_label.cpp board_label.h board_label.ui mill_controller.cpp mill_controller.h mill_model.cpp mill_model.h mill_view.cpp mill_view.h player.cpp player.h token.cpp token.h token.ui ) endif() endif() target_link_libraries(Projekt_Muehle PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. if(${QT_VERSION} VERSION_LESS 6.1.0) set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.Projekt_Muehle) endif() set_target_properties(Projekt_Muehle PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) include(GNUInstallDirs) install(TARGETS Projekt_Muehle BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(Projekt_Muehle) endif() -
Hi,
Just to clear things out, can you properly build that project on the command line for each version of Qt ?
-
I could only get a Qt 5 build using cmake and ninja.
First cmake:
markus@ryzen ~/Qt/Projekt_Muehle $ cmake -G Ninja -S Qt/ -B Qt/build/test_build/ -- The CXX compiler identification is GNU 15.2.1 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.2s) -- Generating done (0.0s) -- Build files have been written to: /home/markus/Qt/Projekt_Muehle/Qt/build/test_buildThen ninja:
markus@ryzen ~/Qt/Projekt_Muehle/Qt/build/test_build $ ls build.ninja CMakeCache.txt CMakeFiles cmake_install.cmake markus@ryzen ~/Qt/Projekt_Muehle/Qt/build/test_build $ ninja [13/13] Linking CXX executable Projekt_MuehleThe files build.ninja and CMakeCache.txt only contain references to Qt 5:
markus@ryzen ~/Qt/Projekt_Muehle/Qt/build/test_build $ grep LINK_LIBRARIES build.ninja LINK_LIBRARIES = /usr/lib64/libQt5Widgets.so.5.15.18 /usr/lib64/libQt5Gui.so.5.15.18 /usr/lib64/libQt5Core.so.5.15.18 markus@ryzen ~/Qt/Projekt_Muehle/Qt/build/test_build $ grep -e Qt5Widgets -e Qt5Gui -e Qt5Core CMakeCache.txt //The directory containing a CMake configuration file for Qt5Core. Qt5Core_DIR:PATH=/usr/lib64/cmake/Qt5Core //The directory containing a CMake configuration file for Qt5Gui. Qt5Gui_DIR:PATH=/usr/lib64/cmake/Qt5Gui //The directory containing a CMake configuration file for Qt5Widgets. Qt5Widgets_DIR:PATH=/usr/lib64/cmake/Qt5Widgets markus@ryzen ~/Qt/Projekt_Muehle/Qt/build/test_build $ grep -e Qt6Widgets -e Qt6Gui -e Qt6Core CMakeCache.txtThese two files were generated by Qt Creator prior to me using the command line:
markus@ryzen ~/Qt/Projekt_Muehle/Qt $ ls CMakeLists.txt .qtcreator/CMakeLists.txt.user CMakeLists.txt .qtcreator/CMakeLists.txt.userI don't think the second file is relevant for the command line cmake.
-
@mgoppelt said in Trying to build a Qt 6 application but getting a Qt 5 application; Qt Creator 19 on Gentoo Linux:
Is there a way to insert a code segment without automatic coloring?
```text
your log
``` -
@mgoppelt And did you install the Qt6 development packages? Remove Qt5 from the CMakeLists.txt and start over with a clean build dir after you made sure the dev packages for Qt6 are installed (and even better - the dev packages for Qt5 are uninstalled).
-
I have the development packages for Qt5 and Qt6. As you mentioned it works when I remove Qt5 from the following statement in CMakeLists.txt.
#find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) #find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets) find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets)The first and third line result in a Qt5 build. The second line results in a Qt6 build. The "Qt version" field in my kit seems to have no influence. I set the value to "None".
The issue is resolved. However in a weird way.
-
M mgoppelt has marked this topic as solved