Build and Run from Command Line
-
What is the correct way to launch from 0 the build and then run of a Qt6 project (Cmake) via command line.
Take for example a QtQuick Application project
How can i from Powershell build and then run the project?
-
@Sebastiano-Zamberlan the process is similar to any other cmake project:
cmake -S /path/to/source-code -B . cmake --build . --parallel --config Release
Then you either run the executable right away or perhaps run deployment first (
windeployqt
). -
@Sebastiano-Zamberlan said in Build and Run from Command Line:
How can I specify that I want it to be compiled with mingw_64
What does this mean? You create a CMakeLists.txt like it's done in QtCreator or any other ide which cmake then processes.
-
@Christian-Ehrlicher, @sierdzio let's take an example, I create a new project ( in this case QtQuick Application )
I leave the code as is and try from terminal to runcmake -S /path/to/source-code -B .
this is what appears to me.
-- Building for: Visual Studio 15 2017 -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19045. -- The CXX compiler identification is MSVC 19.16.27051.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Error at CMakeLists.txt:8 (find_package): By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6", but CMake did not find one. Could not find a package configuration file provided by "Qt6" (requested version 6.2) with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred!
I wanted to know meanwhile how to specify my intention to use mingw_64 as compiler
-
You have to set up your env correctly before by starting the command line through the 'Qt 6.x.x (MinGW64) menu entry. Then the PATH is correctly set up and the mingw compiler is found & used. Start over with a clean build dir.
-
@Christian-Ehrlicher @sierdzio
I tried but still the same error,
I also ran the command--system-information information.txt
and in the .txt the path goes to the Visual Studio
In fact the message that cmake sent me was always:
-- Building for: Visual Studio 15 2017
-
@Sebastiano-Zamberlan Then pass
-DCMAKE_CXX_COMPILER=g++
and make sureg++ --version
print something useful (which should when you set up the env correct). -
Hi,
In addition to @Christian-Ehrlicher, the Qt 6 versions you installed have a
qt-cmake
script that are tuned for the installation they are in. -
@Sebastiano-Zamberlan said in Build and Run from Command Line:
@sierdzio How can I specify that I want it to be compiled with mingw_64
The easiest way, I think, is to use CMake's MinGW Makefiles generator, like:
cmake -G "MinGW Makefiles" ...
As @SGaist wrote, if you're using Qt 6, then you can use Qt's
qt-cmake
wrapper, so:X:\path\to\qt\installation\qt-cmake.bat -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
All
qt-cmake
does (today) is set CMake'sCMAKE_TOOLCHAIN_FILE
variable, so it's equivalent to:cmake.exe -DCMAKE_TOOLCHAIN_FILE="X:\path\to\qt\installation\lib\cmake\qt.toolchain.cmake" -G "MinGW Makefiles" -S <src-dir> -B <build-dir>
Cheers.
-
@Paul-Colby @Christian-Ehrlicher @SGaist @sierdzio
Thank you guys, this information is very helpful,
I was able to launch from the specific terminal, now I want to understand what the "qtenv2.bat" contains and how it acts so that I can make a .bat or a general .py that allows me to launch a build.
-
@Sebastiano-Zamberlan said in Build and Run from Command Line:
I want to understand what the "qtenv2.bat" contains and how it acts
Open it in a text editor
-