# Qt5 CMake can't find C++ STD library if a definition is added in CMakeLists.txt

**URL:** https://discourse.cmake.org/t/qt5-cmake-cant-find-c-std-library-if-a-definition-is-added-in-cmakelists-txt/3061
**Category:** Usage
**Tags:** comp:mingw, comp:gcc, os:windows
**Created:** [April 1, 2021, 8:04am UTC](https://discourse.cmake.org/t/qt5-cmake-cant-find-c-std-library-if-a-definition-is-added-in-cmakelists-txt/3061 "2021-04-01T08:04:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan\_Petrov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ivan_petrov/32/1341_2.png) [@Ivan\_Petrov](https://discourse.cmake.org/u/Ivan_Petrov)
#### Post date: [April 1, 2021, 8:04am UTC](https://discourse.cmake.org/t/qt5-cmake-cant-find-c-std-library-if-a-definition-is-added-in-cmakelists-txt/3061/1 "2021-04-01T08:04:36Z")

</div>

## Here is the problem I am struggling with.

I am using CMake to build my Qt5 GUI project. I am using a custom module [QML-material project](https://github.com/papyros/qml-material) from GitHub.  
The problem is that as it is said in the project documentation - in order to setup the module for your project, you should add a definition:

> add\_definitions(“-DQPM\_INIT\(E\)=E.addImportPath\(QStringLiteral\(\"qrc:/\"\)\)\;”)

But if this definition is added in CMakeLists.txt the project can’t find C++ STD library. If I comment it out the STD features can be used again.

## About the definition meaning.

This macro basically calls addImportPath(“qec:/”) to the argument it is called with. In my case it is in main():

> ```
> // Working example
> QQmlApplicationEngine engine;
> QPM_INIT(engine);
> 
> ```

But if I just change it and call addImportPath straight forward and remove the definition it doesn’t find the custom QML modules.

> ```
> // Not working example
> QQmlApplicationEngine engine;
> engine.addImportPath(QStringLiteral("qrc:/"));
> 
> ```

## My questions:

- Why a definition in CMake can block the project linking with the STD lib?
- Why if I replace the macro with its representation in the main() function it doesn’t work?
- Does anyone have a proposal how to use both the custom module and the STD library together?

NB! The Qt libraries are still visible. The problem is only with the STD.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 2, 2021, 12:02pm UTC](https://discourse.cmake.org/t/qt5-cmake-cant-find-c-std-library-if-a-definition-is-added-in-cmakelists-txt/3061/2 "2021-04-02T12:02:03Z")

</div>

I don’t think compilers generally support callable macro definitions on the command line.

Do you have the error message available?

---

<div class="post-metadata">

### Author: ![Ivan\_Petrov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ivan_petrov/32/1341_2.png) [@Ivan\_Petrov](https://discourse.cmake.org/u/Ivan_Petrov)
#### Post date: [April 2, 2021, 12:14pm UTC](https://discourse.cmake.org/t/qt5-cmake-cant-find-c-std-library-if-a-definition-is-added-in-cmakelists-txt/3061/3 "2021-04-02T12:14:44Z")

</div>

You are right. Yesterday I solved it as I removed the macro. That is a bad workaround of using function like definition, because it is added to CXX\_FLAGS, not to CXX\_DEFINES. If I try to use add\_compile\_definition that adds it to CXX\_DEFINES instead of add\_definition I get a message that function like definitions are not tolerated. So, do not use macros that way 🙂
