# "Cannot find source file" when library is linked to a particular executable

**URL:** https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [February 24, 2026, 8:57am UTC](https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527 "2026-02-24T08:57:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)
#### Post date: [February 24, 2026, 8:57am UTC](https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527/1 "2026-02-24T08:57:30Z")

</div>

I am in the process of migrating an existing project to CMake. In it, I have several libraries and executables;

When I add one of the library targets (let’s say library `lib`) to the main executable (let’s call it `exe`), and “generate”, I currently get a strange error message I cannot find the exact reason for:

```auto
Configuring done (1.1s)
CMake Error in librarypath/CMakeLists.txt:
  Cannot find source file:
    C:/Source/library_autogen/S5YYZ2ZCNV_/qrc_library.cpp

Generating done (8.9s)

```

So, the **executable** linking to the library `lib` causes an error **in the library** , even when the library itself compiled fine before!

I added the main executable last (since it requires basically all other libraries in the project); all libraries build fine; I can create the executable target , but as soon as I add the `target_link_library(exe PRIVATE lib)` call, the CMake generation fails with above error.

I ask myself where the “wrong” search directory comes from (note the missing configuration after `S5YYZ2ZCNV_` - in the ``S5YYZ2ZCNV_Debug` directory, the qrc\_library.cpp file actually exists, created from a previous Debug build. And **how/why**  **can linking** via `target_link_library` call even **trigger a failed search for a source in a dependent library**?

In `lib`, there’s `Resources/library.qrc` , `AUTORCC` is enabled, and as I said, the `lib` compiles fine, and it can also be linked to another executable in another folder.

I tried adding `–log-level=DEBUG` and `–debug-output` to the cmake command line but this didn’t give me any additional info on where this error is coming from.

I’m sure it’s just some stupid error on my end but I can’t figure out how to further debug this…

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)
#### Post date: [February 24, 2026, 1:22pm UTC](https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527/2 "2026-02-24T13:22:39Z")

</div>

I forgot to say, both the library and the executable have AUTORCC set on; but as does the other executable where it works. When I remove the .qrc file from the linked library, the error disappears.

With the help of copilot I found out this is an AUTORCC issue with multi-config generators apparently.

It can be fixed by, instead of adding the .qrc to the sources directly (in the `add_library`call):

```auto
qt_add_resources(mylibrary_QRC resource.qrc)
target_sources(librarytarget PRIVATE ${mylibrary_QRC})

```

Then I don’t get this error… is this a known limitation / issue with AUTORCC? That it sometimes works and sometimes doesn’t?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 24, 2026, 9:23pm UTC](https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527/3 "2026-02-24T21:23:34Z")

</div>

While not a direct answer to your question, if you’re using Qt 6, consider the non-QRC form of `qt_add_resources()`. Instead of listing your resources in a .qrc file and passing that .qrc file to `qt_add_resources()`, add the individual resources directly. The syntax form is something like this:

```cmake
qt_add_resources(target resourceName
    PREFIX prefix # Optional with Qt 6.5 or later
    FILES files...
    [otherOptions...]
)

```

This is the recommended approach for Qt 6. It is more direct and easier to use. Under the covers, it generates a .qrc file internally, but you’re shielded from all those mechanics. It would be interesting to see if you encounter the same error if you added your resources this way instead of giving it your own .qrc file.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)
#### Post date: [February 24, 2026, 9:32pm UTC](https://discourse.cmake.org/t/cannot-find-source-file-when-library-is-linked-to-a-particular-executable/15527/4 "2026-02-24T21:32:31Z")

</div>

Thanks for the hint. For now I’m happy with the workaround, but I will put this on my to do list to try in the near future 😉.
