PDA

View Full Version : How to compile/run simple programs in Windows 8.1 from terminal?



robgeek
29th April 2015, 17:57
Hi!

I have Windows 8.1 64bit and i installed QtCreator 5.4.1 with MinGw 4.9.1. I would like to make some simple console programs using
my text editor, not QtCreator, and compile/run them using the terminal.

//test code.
#include <QCoreApplication>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

cout << "Hello!" << endl;

return a.exec();
}

Terminal command i used:

g++ -o test main.cpp

Error message:

main.cpp:1:28: fatal error: QCoreApplication: No such file or directory
#include <QCoreApplication>
compilation terminated.

I added "C:\Qt\Tools\mingw491_32\bin" in "Environment Variables" so, when i enter with g++ --version in terminal i get "g++ ... 4.9.1".

How can i do what i want?

d_stranz
29th April 2015, 18:37
At least use a Makefile if you don't want to use Qt Creator.

Your problem is that you haven't told g++ where to find your Qt include files. This has nothing to do with where minGW lives, it is all bout telling g++ where to look for what it needs to compile and link your program.

So if you really, really like to type long, long lines at the console prompt and can do it over and over again without making mistakes, you will need to learn the proper command syntax for telling g++ where to find your include files, where to find your library files, and which library files have to by linked into your application to satisfy all the references, all of this using g++ arguments...

Have fun.

In all seriousness, do a simple project using Qt Creator, then run qmake to generate the Makefile(s) for it. That will give you a template to use for future projects that you can develop outside of Qt Creator - simply copy the Makefile(s) to a new project directory and manually edit them to change the source files to whatever is used in the new project. Of course, you'll still have to manually add library names and locations to the linker command in order to get a properly built exe.

Alternatively, start with Qt Creator, let it create a .pro file for your app. You can then run qmake and make / nmake from the command line to generate the Makefile(s) and build the project, respectively.

anda_skoa
30th April 2015, 07:40
Alternatively, start with Qt Creator, let it create a .pro file for your app. You can then run qmake and make / nmake from the command line to generate the Makefile(s) and build the project, respectively.

And once you see how these .pro files look like you can easily created them manually.
That's also documented in every Qt tutorial that preceeds the existance of QtCreator.

Cheers,
-