Results 1 to 3 of 3

Thread: How to compile/run simple programs in Windows 8.1 from terminal?

  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default How to compile/run simple programs in Windows 8.1 from terminal?

    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.
    Qt Code:
    1. //test code.
    2. #include <QCoreApplication>
    3. #include <iostream>
    4.  
    5. using namespace std;
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QCoreApplication a(argc, argv);
    10.  
    11. cout << "Hello!" << endl;
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Terminal command i used:
    Qt Code:
    1. g++ -o test main.cpp
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to compile/run simple programs in Windows 8.1 from terminal?

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to compile/run simple programs in Windows 8.1 from terminal?

    Quote Originally Posted by d_stranz View Post
    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,
    -

Similar Threads

  1. Replies: 4
    Last Post: 18th February 2013, 11:10
  2. Compile and Run Qt programs in ubuntu 12.04
    By stbb24 in forum Installation and Deployment
    Replies: 2
    Last Post: 7th August 2012, 14:43
  3. [WIN XP]installed corectly (?) but cant compile tutorial programs
    By ppn in forum Installation and Deployment
    Replies: 2
    Last Post: 9th September 2007, 09:02
  4. How to run Qt programs----simple one
    By shamik in forum Qt Programming
    Replies: 12
    Last Post: 24th November 2006, 10:58
  5. Can't compile programs in Visual Studio.net 2005
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2006, 15:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.