QtCreator with CMake tries to link the wrong set of Qt libraries. CMake alone works fine.
-
I have a Cutelyst application (which is part of a larger project) that I'm trying to get to run. It works fine if I build and run using CMake alone. But if I try to run from QtCreator, or run the exe that QtCreator built, it tries to mix the 5.12.8 libs from my system at
/usr/lib/x86_64-linux-gnu/
with the 5.15.1 libs from my kit at/home/fahad/Qt/5.15.1/gcc_64/lib/
.Here's my CMakeLists.txt file for the Cutelyst app:
cmake_minimum_required(VERSION 3.19) cmake_policy(SET CMP0048 NEW) project(ServerCutelyst VERSION 0.0.1) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable(ServerCutelyst src/main.cpp src/root.cpp src/ServerCutelyst.cpp src/root.h src/ServerCutelyst.h ) find_package(Cutelyst3Qt5 REQUIRED) find_package(Qt5 COMPONENTS Core Network REQUIRED) target_link_libraries(ServerCutelyst PRIVATE Cutelyst::Core Cutelyst::Server Cutelyst::Session Qt5::Core Qt5::Network) install(TARGETS ServerCutelyst RUNTIME DESTINATION .)
I tried adding:
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/home/fahad/Qt/5.15.1/gcc_64/lib/")
to the CMakeLists.txt file force it to link with the 5.15.1 libs, but that did not fix the issue.
The specific errors I'm getting when I try to run directly from QtCreator are:
/home/fahad/Project/build-Project-Desktop-Debug/bin/ServerCutelyst: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.15' not found (required by /home/fahad/Project/build-Project-Desktop-Debug/bin/ServerCutelyst)
And when I try to run the exe that QtCreator produced on build:
144607:144607 default[fatal] Cannot mix incompatible Qt library (5.12.8) with this library (5.15.1)
How can I force it to build and link with only the 5.15.1 libraries when using QtCreator?
-
Use the correct Kit with the correct Qt version: https://doc.qt.io/qtcreator/creator-project-qmake.html
-
I think that I am using the correct version in my kit.
-
Remove the build dir, make sure the kit really points to the correct Qt version.
-
I haven't solved the problem yet, but I know what caused it.
QtCreator is doing what it's supposed to, that is, finding the 5.15.1 libraries correctly.
My problem is that my Cutelyst version was built with Qt 5.12.8. CMake automatically found and used the Qt 5.12.8 libraries I have installed, which allowed the version built with only CMake to run correctly.
So, I built a Cutelyst version manually using the 5.15.1 libraries instead. I'm having trouble getting CMake to detect that version, but that's a separate issue, so I'll close this one.