How to manually do Run CMake & Run in QT Creator - c++

I'm using QT Creator 3.5.1 on Ubuntu 16.0.4 for a C++ project.
"Run CMake" and "Run" commands work fine in the IDE.
I want to do these two things from a terminal without the IDE. How can I do this?

Qt creator will actually tell you in the 'compile out' pane what commands are run for cmake, usually along the line of cmake --build . -- target all. For running the application you just find the build folder and the executable, alternatively you can peek at the Projects > Run configuration (in case you specify some arguments, but clearly that's not the case)

Note that with a new cmake (>= 3.7) you want to make sure not to use cmake in the build directory that is seen by Qt Creator while that has the project open. Creator will be running cmake in server-mode and that does not like any of the cmake files being changed:-/
Creator should print exactly what it runs in the output pane. For a build that is cmake --build . --target all (in the build directory).
Make sure to run the command in the right directory. For builds that is the top level build directory, while for build targets that can be set in Project mode.
Sometimes you also need some environment variables to be set (to pick up libraries, etc.). Creator does show the environment it uses to build or run things in Project mode.

Related

How to set CMake build configuration in VSCode?

I'm using the CMake Tools extension in VSCode to build and run a C++ project on Windows.
Where do I set if the build configuration should be Debug or Release?
On Build, CMake Tools executes
"C:\Program Files\CMake\bin\cmake.EXE" --build c:/work/foobar/build --config Debug --target ALL_BUILD
How do I get the extension to build with --config Release?
The CMake Tools extension sets up a lot of goodies, including a status bar panel for configuring various aspects of your build(s). In the status line various panels provided by VSCode and extensions can be enabled/disabled. And example including the CMake Tools mini panels appears below:
Note: I am not running VS Code on a Windows machine; mine is MacOS, but the premise is the same.
Anyway, if you click on the portion that says CMake: [Debug]: Ready a select-variant list should open near the top of the IDE in the location you're probably familiar seeing the general Command Palette open. It will look like this:
It is here you can change your selection from one build configuration type to another.
You can also do this via the main command palette by doing the following:
Hit ctrl-shift-P (or cmd-shift-P on MacOS)
Type CMake. The list should filter to just CMake command options.
Scroll the list and choose CMake: Select Variant
The same aforementioned build variant options should present themselves.

Unable to run C++ cmake project in Clion [duplicate]

I'm trying to make CLion use the same version of CMake that I'm using from the command line. In Preferences > Build, Execution, Deployment > Toolchains, I tried setting a custom CMake executable path to /usr/local/Cellar/cmake/3.7.0/bin, but CMake displays a "not found" error on the same page.
For now, I had brew install the same version of CMake that CLion is using: brew switch cmake 3.6.2
But is there a way to make CLion use the version of cmake installed with brew?
Yes, you can set your own cmake binary for use in Clion.
You're on the right track, go to Preferences > Build, Execution, Deployment > Toolchains just as you did, and set CMake executabl -> Custom to
/usr/local/Cellar/cmake/3.7.0/bin/cmake
Note, your're supposed to put the absolute name of your own cmake here, not only the path to the directory containing cmake.

Cannot Run Compiler 'cl' for qt5.10.1 on Windows 10 in terminal

I have never used qt before, but I got a task to build an already existing application for Windows and Mac using the newest version of qt. What I have done so far is:
Installed Visual Studio Professional 2017.
Installed the latest Qt 5 Open Source.
Note: when installing the QT 5 I installed all of the components under QT/ QT 5.10.1 which were: qt 5.10.1 components and under QT/Tools I installed QT Creator 4.6.0 CDB Debugger Support and MinGW 5.3.0 : qt 5 Tools
I cloned the branch from GitHub that I wanted to build to C:/Projects
Then in Git Bash I cd to the project and tried to run qmake. The first time I had this problem:
"bash: qmake: command not found"
After searching into the problem I found out that I haven't added "Qt/5.10.1/msvc2017_64/bin" to PATH and I added it. Now when I echo $PATH I can see the directory added.
Now after bash recognises qmake and I try to run it it says:
Project ERROR: Cannot run target compiler 'cl'. Output:
===================
Maybe you forgot to setup the environment?
I have no idea how to fix the problem due to the fact that I have never used QT to build anything before. Can you help me?
In the read me file for the application I am trying to build it says:
Step-by-step instructions
1. Clone this branch
2. cd into the project
3. Run qmake - this wil generate Makefiles for all of the project's modules
4.Run make (Use the -j4 of -j flags - this greatly speeds up the build process - see the manual page for make for more info). You can also use the -s flag to silence the output - this also wins you a few seconds.
I am a bit puzzled by the instructions, it does not say to run qmake -project anywhere, but there is a qt project file in the directory that I cd to. Does this mean that I don't have to run qmake -project?
Also I have no idea how to run make by using the -j4 and -j flags and how to run flags in general. Could someone help me?
I believe that for the Cannot Run Compiler 'cl' issue I have some kind of a problem with the set up. Did I install too many components or is it to do with the VS setup?
I highly recommend you to install Qt from the Qt installer, and to use Qt Creator.
However, if you want to use it from source, you first need to get a compiler (ex: MinGW). Then you need to execute the instructions, but you need to use a MinGW (or whatever compiler you use) command prompt, which will automatically set the environment variables needed.
Note that this is Windows specific. On mac and linux, the compiler's environment variables are already set in the default command prompt (if there is a compiler, obviously).

Error opening terminal: unknown Qt Creator on MacOs 10.12.4

I have installed QtCreator (4.2.2) and cmake (3.8.1) through homebrew on Mac OS 10.12.4.
I am importing an existing CMake project but when QtCreator is running cmake, I encounter the following error:
Running "/usr/local/bin/ccmake /Users/matthieu/project/source '-GCodeBlocks - Unix Makefiles' -DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++ -DCMAKE_C_COMPILER:STRING=/usr/bin/gcc '-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}' -DQT_QMAKE_EXECUTABLE:STRING=" in /Users/matthieu/project/source/build-decaf-Desktop-Default.
Error opening terminal: unknown.
In QtCreator > Preferences > Environment > System, the terminal is set to:
/Applications/Qt\ Creator.app/Contents/MacOS/../Resources/scripts/openTerminal.command
My TERM env variable is set to xterm-256color. I have tried xterm-color as well but with no luck.
I start to run out of ideas if someone has any suggestions!
I suspect your Qt Creator build settings have been set up to point at ccmake instead of cmake as the CMake executable. Have a look in the Build & Run section under the CMake tab and see what executable has been set. The cmake executable is the command line tool that you want, ccmake is a curses-based UI front end to CMake meant for interactive editing of the CMake cache.
The TERM isn't being recognized. Try stepping down to something more common, like
TERM=xterm

Unable to build for Windows on Linux, with MinGW

Because I am not a Java enthusiast, I decided to use C++ and Qt for one of my projects. However, I came across the big cross-compiling Qt problem, and I am unable to produce an .exe file for Windows users.
My setup
Linux Ubuntu 12.04, with Wine and Qt. qmake -v gives the following output :
QMake version 2.01a
Using Qt version 4.8.1 in /usr/lib/x86_64-linux-gnu
I also have a MinGW32 compiler, which can be found at /usr/bin/i586-mingw32msvc-g++. My Wine drive_c folder contains the following Qt directories :
$HOME/.wine/drive_c/Qt/Qt5.2.0/5.2.0/Src
$HOME/.wine/drive_c/Qt/Qt5.2.0/5.2.0/mingw48_32
The mingw48_32 directory contains the necessary include/ and lib/ directories, which are used in my mkspec file, /usr/share/qt4/mkspecs/win32-x-g++/qmake.conf :
QMAKE_INCDIR_QT = /home/me/.wine/drive_c/Qt/Qt5.2.0/5.2.0/mingw48_32/include
QMAKE_LIBDIR_QT = /home/me/.wine/drive_c/Qt/Qt5.2.0/5.2.0/mingw48_32/lib
The problem
According to most guides I've found about Qt cross-compiling, my setup should be enough to run a simple :
qmake -spec win32-x-g++
make
wine /path/to/my/application.exe
But... nothing's linked. QApplication and every other symbol I use in my program are "not found". No QApplication, no QPushButton, no connect(), no SIGNAL(), no SLOT()...
My objective here is to successfully configure QtCreator to use this setup (in an independent build configuration), so that it can build a Linux executable (through the first and working configuration), and a Win32 .exe (through the MinGW setup above). However, I cannot modify a single build step in QtCreator :
Cannot add a "MinGW" toolchain : it is not available in the "Add" dropdown list.
Cannot change the -spec parameter value in the project build configurations panel. The field is non-editable.
Despite guides and solutions I found all over the Internet, my only solution so far is to send my source code to a virtual Windows machine, and have it create a new project with it. On this VM, I could probably compile for Windows... But of course, this doesn't actually sound like a real "solution" to me...
Is there any way Qt(Creator) has finally made cross-compiling easier now ? I'm getting a bit tired of "symbol not found" errors...
First,
sudo apt-get install mingw-w64
Then, check if Qt Creator finds the toolchain.
Next, until Ubuntu starts providing a mingw-w64-qt package, download the Qt source and build it. This is bound to get messy, and maybe even the simplest thing to do is to install WINE and use a Windows Qt version.