PDA

View Full Version : g++ on Windows (mingw-w64)



mdavidjohnson
13th April 2016, 17:39
I'm using Qt5 on Windows 7 Pro 64-bit. I would like to be able to use g++ to compile Qt5 programs so that I can incorporate assembled assembly code object files at the linkage stage. Using the Notepad example from "http://doc.qt.io/qt-5/gettingstartedqt.html" - I renamed the project as QtNotepad.

When I tried to submit my New Thread to you, the system complained that I had included a total of 8 images and/or videos in my message when only 4 are allowed. Since I had actually included no images or videos at all, I suspect that the system was misreading something. Accordingly, I have attached the body of my New Thread in the attached 20160413QtCentre.txt file.

d_stranz
14th April 2016, 16:48
Sorry, but your original post is about the craziest thing I have read here lately.

First, it is pretty difficult to compile and link Qt projects using the command line. The errors you see are because in your command line, you haven't told g++ anything about where to find the Qt #include files main.cpp references. Read the g++ manual (type "man g++" into Google) and you'll see command line options like "-I<path>", which in your case means "-I<path to qt installation>/include" (where <path to qt installation> is where -you- have Qt installed on your PC).

The problem is, you'll need to type the same line every time you want to compile main.cpp and every other file in your project. g++ won't remember for you what options you gave it the last time you ran it.

And when it comes to linking your compiled files into an executable, you'll need to tell the linker where to find all of the Qt library files it needs. There are g++ command line options for that, too.

But do yourself a favor. Qt has a complete system for building and maintaining projects using qmake and ".pro" project files. It also has Qt Creator, which is a complete IDE (interactive development environment) that helps you edit, maintain, and build projects. Instead of beating your head bloody against the command line, learn to use one of these tools.

Using qmake standalone requires you to learn how to create .pro files and will generate a Makefile for your project that will have all the correct command line options to compile and link projects with g++. All you'll have to do from the command line is type "make" in the directory with your Makefile, and it will create your executable for you.

If you use Qt Creator, it will maintain the .pro file for you in most cases, and will run qmake and make as needed to build your project. Qt Creator was installed when you installed Qt if you used the defaults; look in the Tools\QtCreator\bin directory under the top-level of your Qt install. It should have put a shortcut on your desktop when you installed Qt.