Eclipse, CDT & MingW & MSYS Setup Guide

From WxWiki

Jump to: navigation, search
This article applies to the following versions
Platform wxWidgets MinGW MSYS
Windows XP 2.8.7 5.1.3 1.0.11
Status: Partly Out of Date


Related Articles
Eclipse, CDT & MingW Setup Guide

This guide is supposed to give the advanced computer user a step-by-step documentation on how to get an "operational" C++ integrated development environment (IDE) with support for programming graphical user interfaces - under Windows XP SP2. More specifically, to install & configure a Gnu C/C++ Compiler (MinGW on MSYS) with the Eclipse CDT environment and support for the wxWidgets graphical libraries.


Contents

[edit] Introduction

[edit] Disk Space

The whole installation comprising Eclipse, MinGW and MSYS (without setup or source files) takes up about 235MB on your hard disk. During the installation process you will need about 1.5GB of free hard disk space.

[edit] Intended for Software Versions

To be used only with the following software versions freely available on the web, other versions may or may not work:

MinGW-5.1.3.exe (1) (following are the MinGW packages that I pre-downloaded) - 18.9MB total
 - binutils-2.17.50-20060824-1.tar.gz
 - gcc-core-3.4.5-20060117-1.tar.gz
 - gcc-g++-3.4.5-20060117-1.tar.gz
 - mingw32-make-3.81-2.tar.gz
 - mingw-runtime-3.14.tar.gz
 - w32api-3.11.tar.gz
MSYS-1.0.11-2004.04.30-1.exe (1) - 4MB
jre-6u6-windows-i586-p.exe (2), see also (2a) - 15.6MB
eclipse-cpp-europa-winter-win32.zip (3) - 61.5MB
wxWidgets-2.8.7.zip (4) - 22.2MB

[edit] Prerequisites

This guide is written assuming that all of the above files are in one folder, with the MinGW setup, package and mingw.ini files in a subfolder MinGW. The proper mingw.ini-file that will not try to connect to the internet again is only created if you previously did a download only setup run on a computer with internet access. It might be a good idea to backup that file if you are trying to install on an offline system (once you choose the wrong option during setup, it will keep complaining that you do not have net access).

[edit] MinGW Installation

Please follow the steps described in Installing MinGW under Windows. Note: This tutorial assumes that you have chosen to install MinGW to C:\MinGW

[edit] File: MinGWPathEntries.reg

Windows Registry Editor Version 5.00

; MinGWPathEntries.reg
; Creates the registry entries for environment variables
;   LIBRARY_PATH
;   C_INCLUDE_PATH
;   CPLUS_INCLUDE_PATH
; for a standard MinGW installation into the folder C:\MinGW

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\MinGW\\lib"
"C_INCLUDE_PATH"="C:\\MinGW\\include"
"CPLUS_INCLUDE_PATH"="C:\\MinGW\\include\\c++\\3.4.5;C:\\MinGW\\include\\c++\\3.4.5\\backward;C:\\MinGW\\include\\c++\\3.4.5\\mingw32;C:\\MinGW\\include" 

  • create the file MinGWPathEntries.reg and copypaste the above text into it
  • execute MinGWPathEntries.reg (by doubleclicking)

When asked "Are you sure you want to add the information in <current dir>\MinGWPathEntries.reg to the registry?"

  • select "Yes"

When informed the information has been successfully added to the Registry

  • select "OK"

[edit] MSYS Installation

  • execute MSYS-1.0.11-2004.04.30-1.exe
  • select "Yes"
  • select "Next"

On the license agreement

  • select "Yes"
  • select "Next"

When asked to "Select Destination Directory", leave it at default value ("C:\msys\1.0")

  • select "Next"

When asked "Which components should be installed?", leave selection as is (only 1 installation option anyways, i386)

  • select "Next"

When asked to choose a Start Menu Folder, leave it at default (or change to your liking)

  • select "Next"

On the "Ready to Install" window

  • select "Install"

This will now pop up a DOS window asking you:

 --- DOS Window ---
 "This is a post install process [..]" 
 * just type "y" (without the quotes) there and confirm with Enter
 
 When asked "Do you have MinGW installed?"
 * type "y" (right - no quotes again ;) and confirm with Enter
 
 When asked "Where is your MinGW installation?"
 * type "c:/mingw" (you guessed it - no quotes) and confirm with Enter
 
 Wait a moment, then when asked to "Press any key to continue . . ."
 * press Enter again
 
 DOS window will close now.
 --- End of DOS Window ---

On the setup window

  • deselect the checkboxes for "Welcome to MSYS" and "README"
  • select "Finish"

[edit] Setting MSYS Environment Variable

  • go to Start -> Settings -> Control Panel -> System
  • select the "Advanced" page
  • select "Environment Variables"
  • In the bottom list, labeled "System variables", in the "Variable" column, find and select the entry "Path"
  • below that list, select "Edit"
  • in the field "Variable value", append (CAUTION: DO NOT OVERWRITE!) this to the existing text:
;C:\msys\1.0\bin
  • select "OK"
  • select "OK" (again)
  • select "OK" (third time)
  • reboot your machine, so that the environment variable changes (for MinGW & MSYS) take effect

[edit] Java Runtime Environment Installation

Note: You may already have a Java Runtime Environment installed on your system. In this case it may or may not be necessary to install a newer version.

  • execute jre-6u6-windows-i586-p.exe

On the "Welcome to Java"-window

  • select "Accept >"

This will start the installation process. When it is done

  • select "Finish"

[edit] Installing Eclipse CDT

Create a program folder where you want to put the Eclipse application, e.g.

  • create the folder "c:\eclipse"
  • extract the contents of eclipse-cpp-europa-winter-win32.zip into the folder you created

Create a shortcut for Eclipse on your desktop:

  • right click eclipse.exe in the new folder
  • select "Copy"
  • right click on unused space of your desktop
  • select "Paste Shortcut"
  • right click the newly created shortcut
  • select "Rename"
  • name it Eclipse CDT
  • double-click the shortcut to launch Eclipse for the first time

When asked to "Select a workspace" (this is where all your program sources and project files will be stored)

  • choose a folder that suits you (I recommend "D:\Eclipse Workspace" - or any other drive that is not the system drive)
  • check "Use this as the default and do not ask again"
  • select "OK"

When Eclipse shows the Welcome-Screen

  • close tab by clicking the X to the right of the title "Welcome"

[edit] Verification that the IDE & compiler is working

In the Eclipse Main Menu

  • select "File" -> "New" -> "C++ Project"

In the "C++ Project" window

  • type "configTest" as Project name (note how the grayed-out default location updates as you type)
  • select "Finish"

In the Project Explorer on the left, you will now see the new project named "configTest"

  • right click the project name, select "New" -> "Source Folder"

In the "New Source Folder" window

  • type "src" as Folder name
  • select "Finish"

The new folder "src" now appears in the project explorer

  • right click this folder, select "New" -> "Source File"

In the "New Source File" window

  • type "configTest.cpp" as Source File
  • select "Finish"

This will open a text editor to the right of the Project Explorer, and the text editor window should be labeled "configTest.cpp". In this window

  • enter the following code (make sure to add a newline after the last line of code)
#include <iostream>

using namespace std;

int main()
{
   int i;
   
   for (i=0; i < 15; i++)
      cout << i << " ";

      cout << "done..." << endl;

   return 0;
}

In the Eclipse main menu

  • select "File" -> "Save"
  • select "Project" -> "Build Automatically" to disable it
  • select "Project" -> "Build Project"

If everything is working fine, this should result in the following text in the Console window below your text editor window:

**** Build of configuration Debug for project configTest ****

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\configTest.o ..\src\configTest.cpp
g++ -oconfigTest.exe src\configTest.o
Build complete for project configTest
Time consumed: 453  ms.

Obviously, the "Time consumed" value may vary, depending on your system speed.

  • in the Project Explorer on the left, select the configTest project (alternatively just make sure the active focus is on any file of that project, even the source editor window will do - as long as it's not the Console)
  • from the Eclipse main menu, select "Run" -> "Run As" -> "1 Local C/C++ Application"

This should result in the following output in the console window:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 done...
  • exit Eclipse

Congratulations, you have successfully installed Eclipse CDT and can now use it for development of C/C++ applications that will port easily to other operating systems.

[edit] Some notes on the Eclipse Debug (default) configuration

The default Build configuration includes some debugging settings, this means

  • your executable will be located in the Eclipse workspace subfolder "configTest\Debug\"
  • the executable "configTest.exe" will be considerably larger in size than a release configuration would be

[edit] Stripping Debug Overhead from Executables

You can strip the debug information from the file by

  • opening a DOS prompt (* select "Start" -> "Run", * type "cmd", * select "OK")
  • typing

strip "D:\Eclipse Workspace\configTest\Debug\configTest.exe" (Attention: this time you need the quotes)

  • confirming the command with Enter
  • exiting the DOS prompt by typing (& confirming with Enter)

exit

[edit] Changing Build Configuration

If you want to change the Build configuration for your project to release configuration

  • select the desired project (configTest) in the Project Explorer

In the Eclipse main menu

  • select "Project" -> "Properties" (alternatively, just hold the ALT-key down and hit Enter)

In the "Properties for configTest" window

  • select "C/C++ Build" in the list on the left

In the "C/C++ Build" configuration that is displayed on the right side

  • select "Manage configurations"

In the "Manage configurations..." window

  • choose "Release"
  • select "Set Active"
  • select "OK"
  • select "OK" again to close Project Properties

(Alternatively you can change to Build Configurations by opening the dropdown-menu next to the Hammer-icon in the Eclipse menu bar and selecting the desired configuration - this will also start a build right away)

  • from the Eclipse main menu, select "Project" -> "Build Project"

Your release executable will now be located in the Eclipse workspace subfolder "configTest\Release\"

Note: depending on the Release build configuration settings, this executable may still shrink if you use the strip command on it.

CAUTION: If you change the Build configuration from Debug to Release, or vice versa, make sure to update the compiler and linker flags for your project accordingly for the new configuration (copy your settings from the old one)!

[edit] Building and configuring wxWidgets

  • close Eclipse (if still open)
  • open wxWidgets-2.8.7.zip
  • move the contained folder wxWidgets-2.8.7 to "C:\MinGW" (so that it becomes C:\MinGW\wxWidgets-2.8.7)
  • execute "C:\msys\1.0\msys.bat" (or use the MSYS shortcut on your desktop)

In the command prompt window that opens

  • type (& confirm each line with Enter)
cd /mingw/wxWidgets-2.8.7
./configure --prefix=/mingw --enable-shared

The wxWidgets build will now be preconfigured (with shared libraries) for your system, this will take a few minutes, depending on your system speed. When the configuration script finishes (you see a command prompt again)

  • type (& confirm with Enter)
make

The wxWidgets libraries will now be built, this will take quite a while, depending on machine speed, in the order of 15 minutes. When the build process finishes

  • type (& confirm with Enter)
make install

This will finally copy the libraries to the proper mingw system directories (where your compiler will find them). Sadly, the win32 binaries (.dll-files) will be put in the same directory as the library files that are needed in that directory. However, the dll-files are not needed in there, but have to be in a place that is declared in the PATH environment variable, so they will be moved to the /mingw/bin folder.

  • type in the following (& confirm with Enter)
mv /mingw/lib/wx*.dll /mingw/bin/

Since we already included /mingw/bin ("C:\MinGW\bin") in the path variable, your compiled and linked executable will find the DLLs there now.

Skip the following section if you are not going to use statically linked wxWidgets libraries

If you only want to dynamically link the wxWidgets libraries into your projects,
you can skip the following steps, otherwise you need to reconfigure wxWidgets for
statically linkable libraries as follows:
* still on the MSYS console, type (& confirm with Enter)
./configure --prefix=/mingw --disable-shared
* wait for the configure script to finish, then repeat the commands as before:
make
make install

Skip until here.

  • to close the MSYS command prompt, type (& confirm with Enter)
exit

[edit] Verification that wxWidgets libraries are working

The following steps will explain how to configure a project to use wxWidgets libraries, using the minimal sample delivered with the wxWidgets sources. Please note that text which you are supposed to type is usually embraced in double quotes ("example"), and if not stated otherwise, you are supposed to type it in without these.

[edit] Creating a new Eclipse C++ Project

  • launch Eclipse CDT

In the Eclipse Main Menu

  • select "File" -> "New" -> "C++ Project"

In the "C++ Project" window

  • type "sampleMinimal" as Project name (note how the grayed-out default location updates as you type)

Below the "Project types:" and "Toolchain:" listboxes

  • uncheck "Show project types and toolchains only if they are supported on the platform"

This will display all toolchains in the "Toolchain:" listbox on the right

  • select "Linux GCC" toolchain
  • select "Finish"

In the Project Explorer on the left, you will now see the new project named "sampleMinimal"

  • right click the project name, select "New" -> "Source Folder"

In the "New Source Folder" window

  • type "src" as Folder name
  • select "Finish"

The new folder "src" now appears in the project explorer

  • right click this folder, select "New" -> "Source File"

In the "New Source File" window

  • type "minimal.cpp" as Source File
  • select "Finish"

This will open a text editor to the right of the Project Explorer, and the text editor window should be labeled "minmal.cpp".

  • open WordPad (select "Start" -> "Run", type "wordpad", select "OK")

In WordPad (don't use NotePad, as we need to open a Unix style text file)

  • select "File" -> "Open"
  • in the "Open" dialog, browse to "C:\MinGW\wxWidgets-2.8.7\samples\minimal"

In the "File name:" text field

  • type "minimal.cpp" and confirm with Enter

In the WordPad main menu

  • select "Edit" -> "Select All"
  • select "Edit" -> "Copy"
  • exit WordPad

Back in Eclipse, make sure the empty text editor labeled "minimal.cpp" is still the active one. In the Eclipse main menu

  • select "Edit" -> "Paste"
  • select "File" -> "Save"

[edit] Project Configuration

Now we need to configure the compiler and linker options: In the Eclipse main menu

  • select "Project" -> "Properties" (alternatively, just hold the ALT-key down and hit Enter)

In the "Properties for sampleMinimal" window

  • select and then expand "C/C++ Build" in the list on the left (double click or select the "+")

[edit] Changing Build Configuration to Release

Since you want to build a release file without debug info: In the "C/C++ Build" configuration that is displayed on the right side

  • for "Configuration:", select "Release" from the drop-down menu
  • select "Manage configurations"

In the "Manage configurations..." window

  • choose "Release"
  • select "Set Active"
  • select "OK"

[edit] Tool Settings

On the left side, in the expanded C/C++ Build section

  • select "Settings"

In the "Settings" -> "Tool settings", on the left side

  • select the "GCC C++ Compiler"
  • as "Command:" type
g++ `wx-config --static=no --cxxflags`

In the "Settings" -> "Tool settings", on the left side

  • select the "GCC C++ Linker"
  • change the "Command line pattern:" to
${COMMAND} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}

(The only difference to default is that you move the ${FLAGS} entry from front to back)

Still for the "GCC C++ Linker", under "Miscellaneous"

  • enter the following "Linker flags"
-mwindows `wx-config --static=no --libs`

IMPORTANT: for both, Compiler command and Linker flags, the wx-config statement absolutely HAS to be embraced in so-called backticks (`) - anything else will not work!

Note: If you want a static linking of libraries, you obviously change the static option to yes for both the Compiler "Command:" as well as the "Linker flags"

Another Note: the -mwindows linker flag is to not open a dos window upon program execution because we are developing a graphical application

  • close the "Properties for sampleMinimal" by selecting "OK" on the lower right

[edit] Building the Project

In the Eclipse main menu

  • select "Project" -> "Build Project"

Follow the Console output if you like, the project should now build your executable with dynamically linked libraries (i.e. it won't work if there is no path to the DLLs, but we covered that above).

When compiling and linking has finished, the executable should be located (relative to your Eclipse Workspace main directory) in sampleMinimal\Release\sampleMinimal.exe

[edit] Starting the Executable

In the Eclipse main menu

  • select "Run" -> "Open Run Dialog..."

In the "Run" dialog, on the left side

  • select "C/C++ Local Application" (and read the information on the right side, can't hurt to know)
  • hit the Enter key, this will create a new launch configuration

The project name will be filled in for you. For the "C/C++ Application:"

  • select "Browse"

In the "Open" dialog

  • browse to your Eclipse Workspace, then from there to sampleMinimal\Release\
  • select "sampleMinimal.exe" from the list of files
  • select "Open" (or hit Enter)

It is possible that the "Run"-dialog will now warn you (with a critical symbol) below it's caption: "Program is not a recognized executable." If this is not the case, just select "Run" and you're finished.

In case of that silly warning:

* select "Apply" on the lower right
* select "Close" even lower and more to the right
In the Eclipse main menu
* select "Project" -> "Properties"
* navigate to "C/C++ Build" -> "Settings" -> (on the right) "Binary Parsers"
In the "Binary parser:" list
* uncheck the "Elf Parser"
* check the "PE Windows Parser"
* select "OK" (lower right)

Go back to the Run Dialog: In the Eclipse main menu

  • select "Run" -> "Open Run Dialog..."

In the "Run" dialog, on the left side

  • select your new run configuration ("sampleMinimal Release")

The warning should now be gone, and the "Run" button on the lower right enabled

  • select "Run"

This should now launch the "Minimal wxWidgets App". If so, congratulations, you got yourself a working C++ IDE with wxWidgets support. For future projects, just make sure to copy the project properties as described above.

[edit] Deleting unneeded files

You can now delete the wxWidgets source & build folder "wxWidgets-2.8.7" inside "C:\MinGW\" if you like, it is taking up about 1GB and you won't need it to compile applications for wxWidgets.

However, you may wanna keep the samples folder ("C:\MinGW\wxWidgets-2.8.7\samples"), in case you want to experiment some more with these.

[edit] Troubleshooting and Contact

If anything in this guide is unclear or not working for you, feel free to contact me at larsDOTuffmannATdlrDOTde specifying at what step you're stuck - as long as I don't get too many requests, I'll try to respond. For any questions NOT related to this specific guide, please refer to the appropriate newsgroups, such as:

gnu.g++.help (for gnu-related issues)
comp.unix.programmer (for questions on make and configure scripts)
comp.lang.c++ (for language specific stuff)
comp.soft-sys.wx-windows (for questions about wxWidgets)


[edit] Credits

Image:exclamation.png This section contains information which may be of questionable relevance to the article's subject matter.
Please help improve this article by clarifying or removing superfluous information.
Image:exclamation.png

Eclipse, CDT & MingW & MSYS Setup Guide Credits

[edit] 2008-10-08 14:00 UTC: this page is now in it's second draft version

Image:exclamation.png This section contains information which may be of questionable relevance to the article's subject matter.
Please help improve this article by clarifying or removing superfluous information.
Image:exclamation.png

Release 1 upcoming when inputs / corrections have been finished

Personal tools