CMake locations mixed with Qt5.10 full

Hi everyone,

so I’m trying to compile a Qt5 project with CMake, and I’m facing an issue.

Here’s a little bit of context: I have developped Qt projects for the past several
months without too much problem, but I was doing it from qtcreator, and clicking the
“Build & run” button. This worked. But now, for reasons outside the scope of this post
I need to use CMake to compile and run the project.

So here is the shell.nix file that I have been using for the last few months:

with import <nixpkgs> {};
stdenv.mkDerivation {
	name = "hello-dev-environment";
        buildInputs = [ pkgconfig cryptopp qt5.full qtcreator gdb cmake ];

I have been entering the shell with nix-shell, launching qtcreator and compiling / launching
my programs from qtcreator without too much problems.

Now I have written this CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0)

# MOC files are generated in the build directory, so include it

# Tell CMake to run MOC when necessary

# Tell CMake to run UIC automatically to generate ui files

# Widget finds its own dependency
find_package(Qt5Widgets REQUIRED)

# Create the executable with the sources
add_executable(hello_cmake main.cpp mainwindow.cpp)

# Encapsulates all the setup required to use a Qt module
qt5_use_modules(hello_cmake Widgets)

Now, here is what happens when I run cmake .. from inside the nix shell:

cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /nix/store/gqg2vrcq7krqi9rrl6pphvsg81sb8pjw-gcc-wrapper-7.3.0/bin/gcc
-- Check for working C compiler: /nix/store/gqg2vrcq7krqi9rrl6pphvsg81sb8pjw-gcc-wrapper-7.3.0/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /nix/store/gqg2vrcq7krqi9rrl6pphvsg81sb8pjw-gcc-wrapper-7.3.0/bin/g++
-- Check for working CXX compiler: /nix/store/gqg2vrcq7krqi9rrl6pphvsg81sb8pjw-gcc-wrapper-7.3.0/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:13 (message):
  The imported target "Qt5::Gui" references the file


  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained


  but not all the files it references.

Call Stack (most recent call first):
  /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:156 (_qt5_Gui_check_file_exists)
  /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Gui/Qt5Gui_QICNSPlugin.cmake:4 (_populate_Gui_plugin_properties)
  /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:164 (include)
  /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:87 (find_package)
  CMakeLists.txt:14 (find_package)

-- Configuring incomplete, errors occurred!

Mostly I’m interested in this (from the beginning of the output):

CMake Error at /nix/store/v521qbyfwv3png4bliwgz693v2534ynd-qt-full-5.10.1/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:13 (message):
  The imported target "Qt5::Gui" references the file


  but this file does not exist.

I have found an issue on nixpkgs’ github where the issue is very similar.
Also I have checked: there is no in qtbase plugins directory, but there is one in
qtfull plugins directory.

Quoting github user lucas8 from the link above:

“It seems the errors comes from the fact that when the cmake files are created, they think the plugins are in the qtbase installation, while they are in the qt-full installation.”.

Also he mentions CMAKE_PLUGIN_DIR.

I’m fairly new to nix/nixOS, but by searching a little, I have found a mention of this
CMAKE_PLUGIN_DIR inside file nixpkgs/pkgs/development/libraries/qt-5/5.10/qtbase.patch.
Here is the link on the github repo (for some reason Qt 5.10 disappeared from the repo, so here is 5.11
instead, but the content is similar):

This is where clear water stops for me :confused:

So what I understand and what I’m trying to fix is: qtbase seems to set the root directory of Qt
plugins to be its own “plugins” directory whereas it looks like it should be qtfull's “plugins”

I hope I’m correct, because otherwise I’ve just wasted a few hours!

I haven’t found a way to do this: from the qtbase.patch file, it seems CMAKE_PLUGIN_PATH is set
to NIX_OUTPUT_PLUGIN, so I was trying to find this.
Looking a bit at the directory nixpkgs/pkgs/development/libraries/qt-5/5.10, here is what I

First, the default.nix file mentions:

  • qtbase
  • ../modules/qtbase.nix, and
  • qtbase.patch

so it looks promising.

../modules/qtbase.nix mentions ../hooks/ and also it has this line
NIX_OUTPUT_PLUGIN = $bin/$qtPluginPrefix inside its preConfigure. Not sure what this $bin and
$qtPluginPrefix evaluates to, nor where they are set.
Now in ../hooks/, there are a lot of modifications on QT_-prefixed
environment variables. But not CMAKE_PLUGIN_DIR, nor NIX_OUTOUT_PLUGIN, so I’m not sure this is
relevant, and I don’t want to get lost too deep!

I’m a bit overwhelmed, and when I keep looking, I fall into deeper threads than mention other
environment variables, QT_PLUGIN_PATH, etc. And I’m not sure where the nix-specific stuffs stop
and where the qt-specific stuff begin.

Making a quick github search for qt plugin (here) I find a lot of -DUSE_QT_PUGIN_DIR=OFF, and also a lot of mentions to a mythical ${qtPluginPrefix:?} variable.

I’m not sure what happens: there seems to be as many solutions as there are package developers(!)
but I feel like I’m not too far from “fixing” it.

So does anybody has a clue on how I should continue? Where should I look? Am I even in the right

A couple of things that I think are worth mentionning:

  • at the moment, I enter a nix shell with nix-shell and the shell.nix file from above, from
    there I type the cmake and make commands. I haven’t written a nix derivation to automatically
    build all of this (os am I missing on some env variable or something?).

  • I cannot make a dirty, temporary hack setting an environment variable before running the cmake
    command in my hello directory, because I looked at file
    (from the error message I pasted above), and it’s written set(imported_location "/nix/store/9yiv0c2ga2lmp14m01ncaibmr2ky4jwh-qtbase-5.10.1-bin/lib/qt-5.10/plugins/${PLUGIN_LOCATION}")
    inside it.
    So this Qt5GuiConfig.cmake file is being generated while Qt is built, and it’s somehow called by
    my cmake file. So the only way is to fix the problem at the moment the file is being generated,
    i.e. when qt is being built.

    Sorry this was a pretty long post! I just wanted to explain the context and what I had digged up
    so far.
    I hope someone here as a clue on how to proceed.
    Thanks in advance for taking the time!

While I was waiting for the post to be approved, I kept digging, and found some answers.
IRC user orivej explained to me that the error happened because Qt5GuiConfig.cmake was looking for all files Qt5Gui_*Plugin.cmake in its directory.
An it so happens that package qt5.full has much more of these files in its directory than qt5.qtbase, among which Qt5Gui_QICNSPlugin.cmake and Qt5Gui_QVirtualKeyboardPlugin.cmake.

I hope this helps answer the issue and help making a fix!

1 Like