# How to link debug version of Qt?

**URL:** https://discourse.cmake.org/t/how-to-link-debug-version-of-qt/8492
**Category:** Usage
**Tags:** os:linux, gen:makefiles
**Created:** [July 11, 2023, 8:08am UTC](https://discourse.cmake.org/t/how-to-link-debug-version-of-qt/8492 "2023-07-11T08:08:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![28af2](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/2/e47c2d/32.png) [@28af2](https://discourse.cmake.org/u/28af2)
#### Post date: [July 11, 2023, 8:08am UTC](https://discourse.cmake.org/t/how-to-link-debug-version-of-qt/8492/1 "2023-07-11T08:08:02Z")

</div>

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](https://github.com/JakubMelka/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:

```auto
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:

```auto
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](http://0x0.st/Hjos.txt).

---

<div class="post-metadata">

### Author: ![alcroito](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alcroito/32/186_2.png) [@alcroito](https://discourse.cmake.org/u/alcroito)
#### Post date: [July 11, 2023, 8:59am UTC](https://discourse.cmake.org/t/how-to-link-debug-version-of-qt/8492/2 "2023-07-11T08:59:32Z")

</div>

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

```auto
/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.

> <https://github.com/JakubMelka/PDF4QT/blob/master/vcpkg.json>

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

---

<div class="post-metadata">

### Author: ![28af2](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/2/e47c2d/32.png) [@28af2](https://discourse.cmake.org/u/28af2)
#### Post date: [July 11, 2023, 10:50am UTC](https://discourse.cmake.org/t/how-to-link-debug-version-of-qt/8492/3 "2023-07-11T10:50:49Z")

</div>

That was it. Thanks!
