How to link debug version of Qt?

I have read in the Qt docs that:

The Qt library contains hundreds of internal checks that will print warning messages when a programming error is detected. We therefore recommend that you use a debug version of Qt when developing Qt-based software.

So I want to link a “debug version of Qt” when compiling PDF4QT.

It uses CMake with vcpkg as package manager when configuring its build.

How can I do that?

I have tried appending -DCMAKE_BUILD_TYPE=Debug to the config line, but after using ldd on the generated binary I found out that the Release version of the Qt library is still used.

Here are the exact commands I issued:

cmake -B build_debug -S . -DPDF4QT_INSTALL_QT_DEPENDENCIES=0 -DCMAKE_TOOLCHAIN_FILE=$VCPKG_PATH/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX='/' -DCMAKE_BUILD_TYPE=Debug
cmake --build build_debug --config Debug -j12

Then after compiling if I do for example ldd ./build_debug/Pdf4QtViewerLite/Pdf4QtViewerLite I get:

libQt6Widgets.so.6 => /usr/lib/libQt6Widgets.so.6

So it’s still linked to the release build.

I have tried running the config step with --trace-expand. Here are the logs.

Looking at the logs, you seem to use your system installed Qt, and not one provided by vcpkg.

/usr/lib/cmake/Qt6Core/Qt6CoreTargets.cmake(117):  include(/usr/lib/cmake/Qt6Core/Qt6CoreTargets-relwithdebinfo.cmake )

I don’t know much about the project, but looking at its vcpkg.json file, it does not list qt as a dependency.

I suspect you’ll either have to manually add it there, or convince vcpkg somehow to install qt and use that version.

That was it. Thanks!