SE 2040 Eclipse Notes

Installing Eclipse with C++ Support on Windows

These directions are based on Eclipse CDT Neon. See below for directions for installing Eclipse CDT on a MacBook. Note that you do need to install Eclipse CDT; the version of Eclipse that you installed for Java development will not work with C++. See here for setting up Eclipse once it is installed and below for other FAQs.

  1. Open a command prompt (Start | All programs | Accessories | Command Prompt). You will probably want to right click on it in the accessories folder and select "Pin to start" to make it easier to access.
  2. Type
            java -version
    
    and confirm you have version 1.7 or later installed.
  3. We will use Chocolatey to install C++ because doing it directly from mingw.org is much harder.
    To install Chocolatey,
    1. Right click on your command prompt icon in your start menu and select "Run as administrator".
    2. Visit chocolatey.org, click on "Install Chocolatey Now"
    3. Scroll down to the section "Installing Chocolatey" and click on cmd.exe for the directions to install with cmd.exe.
    4. Click on the icon to copy the text and paste it into your command prompt.
    5. Close the command prompt and then reopen it, again with administrator access. Type
              choco
      
      If you get a command not found error, ask for help.
  4. Still in the administrator-level command prompt, execute the command
            choco install mingw
    
    in the administrative command prompt. "MinGW" is "Minimalistic GNU for Windows."
  5. After it is installed, open a new command prompt (it does not have to be an administrator prompt) and type
            gcc --version
    
    If you get an error about the command not being found, open the System dialog (it can generally be found by right clicking on the windows start icon), selecting Advanced, Environment Variables, and editing the PATH variable to add the folder containing gcc.exe. In many cases this folder will be c:\tools\mingw64\bin. Close the dialog, open a new command prompt (so the new setting for PATH becomes effective), and confirm gcc (and g++) are installed.
  6. Visit the folder containing gcc. If you are not sure where it is, type the command
            where gcc
    
    and Windows will display the folder name. Browse to that folder and make a copy of gcc.exe as mingw32-gcc.exe. The location of this file is used by Eclipse to find the MinGW libraries, so skipping this step can result in programs compiling but not running.
  7. Still in the folder containing gcc.exe, type
            copy mingw32-make.exe make.exe
    
    This will allow you to type make at the command prompt to build your projects (relevant later in the term).
  8. Other packages you could consider installing:
            choco install -y notepadplusplus        # Notepad++
            choco install -y vim                    # edit using vi
            choco install -y git                    # works, but does not provide
                                                    #   the explorer context menus
            choco install -y gow                    # many unix utilities
            choco install -y sqlite sqlite.shell    # SQLite support
    
  9. Important: reboot your computer to so that the new setting of PATH is available to all applications.
  10. Download Eclipse IDE for C/C++ Developers from here. Make sure you get the one for C/C++ developers - the Java one will not work for SE 2040.
  11. Unpack the .zip to a folder. Make sure the folder does not have a space in it such as "My Documents" or "More Applications". I use c:\apps to avoid cluttering up C:\.
  12. Open Windows File Explorer and browse to the Eclipse executable. Right click on it and select "pin to start"
  13. Start Eclipse.
    1. It will prompt you for a workspace. This is where temporary build files will be placed and is the default location for project sources. You can simply use the same workspace for all projects and save source files inside a separate repository.
    2. Click on the workbench icon in the upper right.
    3. Turn off hard tabs by visiting Window|Preferences, and selecting
      • General | Editors | Text Editors | check Insert spaces for tabs
      • C/C++ | Code Style | Formatter; click the New button to create a new profile, then OK to continue. The system will pop up a formatting dialog; on the Indentation tab, change the policy to "Spaces only"
      Both are needed: the first only affects regular text files. Note that you may need to similar steps to avoid tabs with Java files.
    4. Make c++14 the default for the editor:
      1. Windows|Preferences
      2. Expand C/C++ and Build and then click on Settings
      3. Select the Discovery tab
      4. Click on CDT Cross GCC Built-in Compiler Settings
      5. in the "Command to get compiler specs" box add
                -std=c++14
        
        between -dD and "${INPUTS}".
      You may need to restart Eclipse to apply the setting to current projects. But while you're in the neighborhood, you might also set GCC to be the default compiler for new projects by clicking on New C/C++ Project Wizard, then on MinGW GCC, and finally on the Make toolchain(s) preferred button.
    5. Open File | New | C++ Project, select Hello World C++ Project, MinGW GCC, and set the project name.
      • Do not put spaces in project names. Including spaces in folder and file names often causes command-line tools to fail. If you really need a word separator in a name, consider using the dash ('-') instead.
      • If you plan to use your own repository manager such as git or just want to control where your files are located, deselect "Use default location" and browse to where you want your project to live within your repository.
      • If MinGW GCC is not an option when you create a new project, this probably means you skipped the step to create mingw32-gcc.exe above. It should work to do that step (now) and restart Eclipse.
    6. Select Project | Build All
    7. Click on the Green run arrow, your output should show in the console at the bottom of the screen.
      • If you get a "Launch failed. Binary not found.", this means you tried to skip the Build All step. Once the project has been built once, you can skip that step. But you must explicitly build the project for the first time.
If you use any c++14 features in a project, do
  1. Project | Properties
  2. Expand C/C++ Build and click on Settings
  3. Under GCC C++ Compiler click on Dialect
  4. Set the Language standard to ISO C++1y
  5. Click OK
(Note: if C++14 doesn't work, try C++11; it's unlikely that you will be making extensive use of features specific to C++14.)

More Information

C++ IDE Frequently Asked Questions

Many employers do appreciate seeing Eclipse experience on a resume.

MacBook Installation Directions

This section gives hints for installing EclipseCDT on a MacBook. We can only provide limited help for MacBook users; if you have troubles you cannot solve, please use the laptop provided by MSOE.

Follow the above steps with the following differences: