JMU JMU - Department of Computer Science
Help Tools
Installing a C++ Development Environment for MS-Windows (MinGW, MSYS, jGRASP)


1 Introduction

There are an enormous number of development environments for C/C++ programmers, some of which are freely available and some of which are commercial products.

This document describes the installation and use of one freely available environment that consists of:

running under MS-Windows.

2 Getting Started

There are a variety of ways to install these three components. This document describes one of them. The first thing you need to do is download the following installation files:

3 Installation

  1. Follow the "Graphical User Interface Installer" instructions on the MinGW Getting Started page. At a minimum, you should install mingw32-base, mingw32-gcc-g++, and msys-base. (You can install other components later, if needed.)
  2. Install jGrasp.
  3. Run jGrasp.
  4. Click on Settings, pull down to Compiler Settings, and pull down to Workspace.
  5. Change the language to C++.
  6. Select "g++ - MinGW (C:\mingw\bin)", click on Use, and click on OK.

If you want to use the make utility from within jGrasp you will also need to do the following:

  1. Run jGrasp.
  2. Click on Settings, pull down to PATH/CLASSPATH, and pull down to Workspace.
  3. Add a new entry to the PATH that points to the bin directory under the msys directory. (The location of which will vary depending on how you installed MSYS. One possibility is c:\msys\1.0\bin)

You are now ready to start developing in C/C++ and you have three ways to proceed, depending on your personal preferences. You can work from the standard command shell (using an editor of your choice), you can work from the MSYS shell (using an editor of your choice), or you can use jGrasp.

4 Testing the Installation Using jGrasp

To test your installation using jGrasp:
  1. Run jGrasp.
  2. Click on File, pull down to New, and pull down to C++.
  3. Copy and paste the following fragment:
    #include <iostream>
    
    int main(int argc, char **argv)
    {
       std::cout << "Testing 1, 2, 3\n";
       return (0);
    }
    	  
    into the editing window.
  4. Click on File and pull down to Save As and name the file testing.cpp.
  5. Click on Build and pull down to Compile and link.
  6. Click on Build and pull down to Run.

Depending on what else is installed on your computer, this will either cause the message "Testing 1, 2, 3" to be written into the jGrasp Run I/O window or will open a command shell window and execute the program there.

5 Working from within jGrasp

You can compile, link and run applications written in C++ from within jGrasp. However, because of the nature of the C++ development process, it is not as simple as it is with applications written in Java.

The Build menu contains the entries Compile, Compile and Link, Make, and Run (among others). The Compile entry can be used to compile an individual source file. The Compile and Link entry is not very useful because the process of indicating which files should be linked is akward. Hence, it is best to use the Make entry.

The Make entry simply calls the make utility (which must be in your path -- see the discussion in the installation instructions above). The make utility uses a makefile (with a default name of makefile) in the working directory. You can, of course, create/edit this file with jGrasp.

Note that when you run an application from withing jGrasp it assumes that the executable is named a.exe.

6 Working from the MSYS Shell

MSYS is a Unix-like command shell (an alternative to the cmd.exe and command.com provided with MS-Windows) that allows you to develop C++ programs as you would using a UNIX/Linux command shell. You can start this command shell either by running the msys.bat file (e.g., in c:\msys\1.0\bin). For convenience, you may want to create a "shortcut" to msys.bat (right-click on the msys.bat in file explorer and pull down to Create Shortcut) and put it on your desktop.

Once you have the shell running, you can use the text editor of your choice (e.g., VIM to create files, the G++ compiler to compile and link, and the GNU make utility to manage projects.

Note: By default, MSYS will create a "home" directory (that it will start in) for you under the directory in which it was installed. To use an alternative directory for your "home" you must set a Windows environment variable named HOME. For example, to use the directory c:\users\bernstdh set HOME to c:\users\bernstdh from the "Control Panel". (Your "home" directory is also where you would put your .profile file.)

7 Working from the MS-Windows Shell

The MS-Windows shell (i.e., cmd.exe can be accessed from the Start menu by choosing run and entering cmd.exe in the dialog box. To use the MS-Windows shell to compile and link C++ programs you need to have both the bin under MinGW (which may be something like c:\MinGW\bin depending on where you installed it) and the bin directory under MSYS (which may be something like c:\msys\1.0\bin depending on where you installed it) in your PATH.

Once you have the shell running, you can use the text editor of your choice (e.g., VIM to create files, the G++ compiler to compile and link, and the GNU make utility to manage projects.

8 Issues

You should be aware of the following issues:
  1. Many applications (including many development tools) use the space character as a delimiter. This means that, in general, it is a bad idea to use spaces in file names and/or directory names.
  2. See 1.

Copyright 2019