Howto cross-compile a qt application with mingw

I try to create a development envrionment for my qt application. As an example I use the following shell.nix file:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    pkg-config
    qt5.qmake
    cmake
  ];

  buildInputs = with pkgs; [
    gcc
    qt5.full
    qt5.qtcharts
  ];
}

This works as long as I compile for my own architecture. I can do nix-shell then qmake && make.

When I change the line pkgs.mkShell to pkgs.pkgsCross.mingwW64.mkShell and do nix-shell all seems to work well. But when I call qmake I get the following error message:

Project ERROR: Cannot run compiler 'g++'. Output:
===================
===================
Maybe you forgot to setup the environment?

What am I doing wrong? I thought pkgsCross.mingwW64 would take care off configuring the environment correctly. It does set $CC and $CXX to x86_64-w64-mingw32-gcc/g++ and those binaries are in $PATH but still something seems to be missing to satisfy qmake.

Any ideas?
Thanks in advance

Wondering if you ever made any progress on this

I did not make much progress. I changed myshell.nix file to:

{ pkgs ? (import <nixpkgs> {
  overlays = [
    (final: prev: {
      qt5 = prev.qt5.overrideScope' (qfinal: qprev: {
        qtbase = qprev.qtbase.override {
          postgresql = null;
          libmysqlclient = null;
          withGtk3 = false;
          cups = null;
          dconf = null;
          gtk3 = null;
        };
      });
    })
  ];
}).pkgsCross.mingwW64 }:

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    pkg-config
    qt5.qmake
  ];

  buildInputs = with pkgs; [
    qt5.full
    qt5.qtcharts
  ];
}

But than I got the infinite recursion encountered... error. After that I came to the conclusion that the qt packages in nixpkgs were not built with cross compiling to windows in mind.

Since I did not have much time I gave up on this and used mxe in a docker container.

If you get it working please let me know. I would still prefer to use nix than my docker solution.

2 Likes