PDA

View Full Version : compile with minGW ??



eric
8th November 2007, 00:57
Hi,

I'd like to know how to copile a simple QT program such as the one below using minGW command line. I've never used command line before and I'm very new to Qt.
More specifically:
1. Do I need to make a "hello.pro" file and subsequently a "makefile" (with qmake) for
this simple project
2. How do you then use command line? What do you type in?
When I do C:\Qt\4.3.2\myfolder> g++ -c hello.cpp
the copiler complains just about every Qt-related stuff in the program.
I don't know how to compile things that are not pure C++ and involve linking more
than one file (especially if the file is a makefile).

// hello.cpp
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QPushButton hello("Hello");
hello.show();
return app.exec();
}

jacek
8th November 2007, 01:08
Even if you are familiar with command line tools, you should use qmake. It's pretty straightforward:
C:\...> qmake
C:\...> make

If you don't have a .pro file, you can invoke "qmake -project" in the directory with your sources to generate one.

tommy
8th November 2007, 01:17
Hi Jacek,

I see that Eric is trying to figure out exacly the same thing as me.
Once you have your makefile, how do you then use it in your command line? What's the syntax? Where do you put the name of the makefile when you compile.

Thanks again Jacek!

Tommy

natbobc
8th November 2007, 01:39
Hi Jacek,

I see that Eric is trying to figure out exacly the same thing as me.
Once you have your makefile, how do you then use it in your command line? What's the syntax? Where do you put the name of the makefile when you compile.

Thanks again Jacek!

Tommy

The make command looks for a file named "Makefile" by default. You can however specify other makefiles with the -f option. If you add source files you will generally want to update your project file. When I start a project using QT I create all of my source files as empty skeletons. Running the following should provide you with a compiled project.


qmake -project // generates your project file
qmake // generates your make file
make // builds your app

Any time you change your source (ie/ save) run make. If you add files, either manually update the PROJECTNAME.pro file (preferred esp. if you start working with plugins), or rerun all 3 commands. I believe on Windows you will also need to ensure the bin folder in QT is located in your path otherwise it won't find the required DLL's. Your programs exe will generally be placed in the "release" folder.

Regards,

Nate

jacek
8th November 2007, 01:41
Once you have your makefile, how do you then use it in your command line? What's the syntax? Where do you put the name of the makefile when you compile.
By default make looks for a file called "Makefile" in the current directory, but you can also use -f option to tell it which file to read (for example "make -f Makefile.Release").