IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Install Qt on a Mac with Xcode or QtCreator

Date de publication : 07 february 2009 , Date de mise à jour : 13 february 2009


III. Your first compilation from the terminal
III-A. Creation of a source file
III-B. Project file creation and compilation
III-C. Explanations of commands


III. Your first compilation from the terminal

icon Terminal
It is possible to compile sources directly from the terminal, a little bit like under windows (DOS command window) by using the make command (nmake under windows if you are using Microsoft's compiler).


III-A. Creation of a source file

Before creating a source file anywhere (usually on the desktop) and take the risk of having a complete mess after generating files , we will create a folder for the projet, what about 'QtProjects' in /Developer and the famous test folder that every developper has created at least once in his life ? 01_test :D

info WARNING : avoid files and folder names containing spaces !
Create a new text file and save it as main.cpp. Then copy-paste the code below and save again :
main.cpp

					#include <QApplication>
					#include <QPushButton>
							
					int main(int argc, char *argv[])
					{
						QApplication app(argc, argv);
						QPushButton button("Ca marche !");
						button.show();
						return app.exec();
					}
				

III-B. Project file creation and compilation

Now we must create the project file, "qmake" command will do it for us. Open the terminal (call it with Spotlight or under /Applications/Utilities). Go to folder /Developer/QtProjects/01_test with command "cd /Developer/QtProjects/01_test".

info You can also type in "cd "and drag the folder 01_test as shown on the following screenshot :
Drag and drop of a folder into the terminal, very usefull to get rid of spaces in file/folder names
Drag and drop of a folder into the terminal, very usefull to get rid of spaces in file/folder names
Enter the following commands :
qmake -project to create the project file (by default 01_test.pro)
qmake -spec macx-g++ to create the makefile
make to compile
the executable file is created and appears in the same folder as the sources. Here is the result :

Qt executable test file on Mac
Qt executable test file on Mac
Before going to the next step, deleted all generated files (keep main.cpp), that is not required but it will train you to enter the commands.


III-C. Explanations of commands

Before going to the next step, it would be wise to understand the qmake command options.
Documentation can be found on Trolltech's website (or Nokia if ou prefer) qmake-running.

As said into the documentation, in the default mode, qmake will use the description in a project file to generate a Makefile, but it is also possible to use qmake to generate project files.
The fact of generating a project file or a Makefile is called the 'mode'.
The first command using -project explicitely specifies to create a project file.
The second one specifies -spec. Documentation says :
-spec spec
qmake will use spec as a path to platform and compiler information, and the value of QMAKESPEC will be ignored

QMAKESPEC's documentation says :
The name of a platform-compiler combination. In this case, qmake will search in the directory specified by the mkspecs subdirectory of the data path specified when Qt was compiled (see QLibraryInfo::DataPath).
We still have to find the supported combination platform-compiler on Mac. Here is the page : supported platforms We can find macx-g++.
Now that I've made you search everywhere, here is another explanation : qmake platform notes :
Where the source package typically uses the macx-g++ specification, the binary package is typically configured to use the macx-xcode specification It means that if you don't specify -spec macx-g++, qmake will generate an Xcode project file by default.

 

Valid XHTML 1.1!Valid CSS!

Les sources présentées sur cette page sont libres de droits et vous pouvez les utiliser à votre convenance. Par contre, la page de présentation constitue une œuvre intellectuelle protégée par les droits d'auteur. Copyright © 2009 Michel LIBERADO. Aucune reproduction, même partielle, ne peut être faite de ce site ni de l'ensemble de son contenu : textes, documents, images, etc. sans l'autorisation expresse de l'auteur. Sinon vous encourez selon la loi jusqu'à trois ans de prison et jusqu'à 300 000 € de dommages et intérêts.