MinGW C/C++ Compilers

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

MinGW C/C++ Compilers

Post by jussij » Tue Jul 30, 2013 11:47 am

The steps below describe how to get the MinGW C/C++ compiler up and running on Windows.

Step 1) Download the mingw-get-setup.exe automated GUI installer assistant to install the MinGW software.

This is a minimal Web installer that will bring up an install Wizard to guide you through the installation process:
mingw.png
mingw.png (20.95 KiB) Viewed 600 times
Step 2) Run installer assistant downloaded from the above step:

Code: Select all

c:\temp\mingw-get-setup.exe
Follow the steps in the wizard taking note of the install folder used. Lets assume the install folder used as shown below:

Code: Select all

C:\Program Files\mingw32\
Step 3) Once the install is complete use the Windows Control Panel to open up the System icon and use the Environment button found in the Advanced settings to add the bin install folder from the previous step to the PATH environment variable.
system.png
system.png (48.37 KiB) Viewed 2002 times
IMPORTANT: Take extreme care when editing this PATH environment variable. Only add to it. Never delete from it.

More details about the PATH can be found here: viewtopic.php?f=5&t=6176

For the installation folder noted earlier, the bin folder to be added would be:

Code: Select all

C:\Program Files\mingw32\bin
If the install folder had been this:

Code: Select all

C:\mingw32\
Then the bin folder that needs to be added would be:

Code: Select all

C:\mingw32\bin
In both cases make sure the bin folder exists and contains the g++.exe C++ compiler and the gcc.exe C compiler file.

In the steps that follow it is assumed the GNU C++ compiler is being used, but if the GNU C compiler is required, just replace the g++.exe command with the gcc.exe command.

Step 4) Test the PATH settings using the Windows Start Button and run the cmd executable to bring up a command prompt.

From inside that command prompt type in this C++ compiler command line:

Code: Select all

g++.exe --version
Running this command line should result in the following output:

Code: Select all

g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To test the C compiler use this command line:

Code: Select all

gcc.exe --version
If you don't see output for either of those commands then the PATH has not been correctly configured or the installation has not worked.

Step 5)
Test the compiler by creating a simple c:\temp\test.cpp test file using the C++ code shown below:

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world..." << endl;
    return 0;
}
From inside the command prompt test the compiler by running the following commands:

Code: Select all

cd c:\temp\
g++.exe test.cpp -o test.exe
dir test.exe
Those commands change to the c:\temp\ folder and then run the C++ compiler to compile and link the c:\temp\test.cpp file to produce the c:\temp\test.exe executable.

Running those commands should produce the following output:

Code: Select all

c:\>cd c:\temp\

c:\Temp>g++.exe test.cpp -o test.exe

c:\Temp>dir test.exe
 Volume in drive D is DATA
 Volume Serial Number is 06EC-1105

 Directory of c:\Temp

21/05/2016  02:30 PM         2,707,662 test.exe
               1 File(s)      2,707,662 bytes
               0 Dir(s)  1,824,970,645,504 bytes free
Running the c:\temp\test.exe executable produced should result in this output:

Code: Select all

Hello world...
Extra Zeus IDE Configuration
To run the compiler from inside the Zeus IDE you will need to make a configuration change to the C/C++ Document Type.

To make this change, use the Zeus Options, Document Types menu, edit the C/C++ Document Type and in the Compiler section define the compiler command line as:

Code: Select all

g++.exe "$fn" -o "$fdd$fb.exe"
This command will compile and link the current file and produce and executable in the same folder as the current file.

NOTE: The options above are for the GNU C++ compiler. To use the GNU C compiler you need to use the gcc.exe and set the options for that compiler. More details on options for the GNU C compiler refer to this link.

If you only want to syntax check the current file change the command line to be this:

Code: Select all

g++.exe -c "$fn"
To make the compiler always compile as c++, to increase the warning levels and to turn on the C++11 features just change the command line to be this:

Code: Select all

g++.exe -x c++ -Wall -std=c++11 "$fn" -o "$fdd$fb.exe"
To make the compiler treat the file as C code change the command line to be this:

Code: Select all

g++.exe -x c -Wall -std=c90 "$fn" -o "$fdd$fb.exe"
For more compiler options use the Tools, DOS Command Line menu and type in this command line:

Code: Select all

g++.exe --help
To test the compiler settings use the Templates button found on the navigator panel, select the C/C++ Document Type from the list at the top and click on the New File template.

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world..." << endl;
    return 0;
}
Save the resulting file to c:\temp\test.cpp and then use the Compiler, Compile menu to compile the file.

This will produce a c:\temp\test.exe and again use the DOS Command Line menu to run the executable and you should see this output:

Code: Select all

Hello world...
Running the Executable for Inside Zeus
To make it easier to run the executable for inside Zeus, it comes with a macro that will try to run an executable that corresponds to the name of the currently active file.

By this, it is assumed the compiler configuration is setup to produce an executable in the same directory as the current document and the name the executable being created is using the base name (i.e.$fdd$fb.exe) of the document being compiled, as described earlier.

This allows Zeus to run the executable and capture it's output be using the Macros, Execute menu or the Macros, Execute tab found in the Navigator panel.

NOTE: If the executable runs but does not produce any output refer to the Mysteries of MinGW post for details on how to fix this.

Cheers Jussi

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests