Cross-compile

Qt VS Tools support cross-compilation of Qt projects by integrating Qt/MSBuild and the Linux development VS workload. This enables you to develop widget-based and Qt Quick applications that target both Windows and Linux, including embedded devices.

Set up cross-compilation

To develop Qt applications for Linux using Visual Studio:

  1. Install the Desktop development with C++ and Linux development with C++ workloads.
  2. Enable the Windows Subsystem for Linux (WSL) and install a Linux distribution.
  3. Or, create a connection to a remote Linux build server.
  4. Add the cross-compiled Qt build that resides in a WSL instance or the remote build server.

Add Qt version for cross-compilation

To add a Qt version for cross-compilation:

  1. Go to Extensions > Qt VS Tools > Qt Versions
  2. Select to add a new Qt version.

    {Qt Versions}

  3. In Version, enter a name for the Qt version. If you add the path to Qt first, this field is filled automatically.
  4. In Host, select Linux WSL or Linux SSH.
  5. In Path, enter the path to the Qt installation.
  6. In Compiler, enter the cross-compiler to use. The default value is g++.

Compile on WSL

Using a WSL instance to run the cross-compiler is faster than using an SSH connection to a build host. When using SSH, MSBuild must first upload the source files to the remote host, whereas WSL mounts local drives in /mnt, making file access instantaneous.

MSBuild assumes that paths specified in options are local paths and maps them to corresponding Linux paths rooted on /mnt. For example:

C:\include\foolib maps to /mnt/c/include/foolib

Using absolute Linux paths as value of Extensions > Qt VS Tools > Options > Qt/MSBuild can lead to wrong mappings. For example, /home/user/raspi maps to /mnt/home/user/raspi.

To avoid this issue, create symbolic links in /mnt to other top-level directories in the WSL instance file system.

See also Tutorial: Qt Quick debugging, Debug applications, Debug on Linux, Enable QML debugging, Building, and Debugging Qt Quick applications.

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.