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 SP3 2.8.9 (newest: 2.8.10) 5.1.4 1.0.11
Status: Partially out of Date


Related Articles
Eclipse, CDT & MingW Setup Guide
Credits: Eclipse, CDT & MingW & MSYS 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 SP3. 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 MinGW, MSYS, Eclipse & wxWidgets (with wxWidgets samples, but without setup or source files) takes up about 238MB 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.4.exe MinGW group (1) (following are the MinGW packages that I pre-downloaded) - 15.6MB total
 - binutils-2.17.50-20060824-1.tar.gz
 - gcc-core-3.4.5-20060117-3.tar.gz
 - gcc-g++-3.4.5-20060117-3.tar.gz
 - mingw32-make-3.81-20080326-2.tar.gz
 - mingwrt-3.15.1-mingw32.tar.gz
 - w32api-3.12-mingw32-dev.tar.gz
MSYS-1.0.10.exe MSYS direct link (2a) - 2.67MB
Updates to MSYS:
 - msysCORE-1.0.11-2007.01.19-1.tar.bz2 msysCORE 1.0.11 direct link (2b) - 1.84MB
 - msysDTK-1.0.1.exe msysDTK direct link (2c) - 9.82MB (Note: not needed & not installed here)
jre-6u12-windows-i586-p.exe Java SE Runtime Environment (3), see also (3a) - 15.5MB
eclipse-cpp-ganymede-SR2-win32.zip Eclipse Ganymede (4) - 68.6MB
wxWidgets-2.8.9.zip (5)  wxWidgets direct link (5a) - 21.6MB

Note that trouble finding libraries at compilation time later in this guide may be attributable to the use of MSYS 1.0.10 (without the 1.0.11 update).

[edit] Prerequisites

This guide is written assuming that all of the above files are available (with the exception of msysDTK-1.0.1.exe). You will need a file archiving software. One free software solution is 7-zip.

Please also note the section about MinGW Offline Installation.

[edit] MinGW Installation

Please follow the steps described in Installing MinGW under Windows.

Note: This guide assumes that you have chosen to install MinGW to C:\MinGW

[edit] Optional: MinGW Offline Installation

If you want to perform an offline installation of MinGW, you can do this by following the guide Installing MinGW under Windows on a computer with internet access, but selecting Download only, then proceeding until the installer exits normally (after downloads finish). Now copy all downloaded files, the installer executable and the newly created mingw.ini to the PC where you want to perform the offline installation and restart the installer there.

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. It might be a good idea to backup that file since once you choose the wrong option during setup, the installer will keep complaining that you do not have net access.

[edit] Setting MinGW Environment Variables

  • create the file MinGWPathEntries.reg and copypaste the following text into it:
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" 

  • 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.10.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 (Installation for 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] MSYS Update to 1.0.11

  • open msysCORE-1.0.11-2007.01.19-1.tar.bz2 and extract msysCORE-1.0.11-2007.01.19-1.tar
  • open msysCORE-1.0.11-2007.01.19-1.tar and extract the contents to C:\msys\1.0 (overwrite existing files)

[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
  • NOTE: If you have another build application that has a make.exe in your path, make sure that "C:\msys\1.0\bin" precedes the other path. To see if you already have make.exe in your path, open a CMD window and type "make" at the prompt.
  • 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-6u12-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. c:\eclipse
  • extract the contents of eclipse-cpp-ganymede-SR2-win32.zip (main eclipse folder)
  • copy the contents of the extracted eclipse folder into the program 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 Are 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] Note About Changing File Templates

If you would like to change the default text that Eclipse uses for newly created files,

  • go to "Window" -> "Preferences"
  • expand "C/C++" -> "Code Style" & select "Code Templates"
  • on the right side, expand "Files"
  • expand the file type you like to change, select the default template and change the "Pattern" below

[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 the 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

You will need a file archiving software. One free software solution is 7-zip.

  • close Eclipse (if still open)
  • open wxWidgets-2.8.9.zip
  • move the contained folder wxWidgets-2.8.9 to "C:\MinGW" (so that it becomes C:\MinGW\wxWidgets-2.8.9)
  • 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.9
./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 you should move them 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.

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

Caution: If you plan to use other libraries which depend on wxWidgets (e.g. PLplot), be aware that although this method which uses ./configure to create the makefiles will result in Windows libraries, it will not place them in the same paths as if you were to use mingw32-make directly with the pre-existing makefiles. The location of build.cfg may also be a significant factor. CMake, for example, can search for wxWidgets via two independent methods labeled 'unix' and 'win32'. This ./configure method is not compatible with the 'win32' search method.

[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 "minimal.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.9\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"

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


If you chose to follow this guide loosely and compiled/linked only static libraries, you will see errors such as the following in the Console window:

g++ -L/mingw/lib -mwindows `wx-config --static=yes --libs` -o"sampleMinimal"  ./src/minimal.o
./src/minimal.o:minimal.cpp:(.text+0x70): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)'
./src/minimal.o:minimal.cpp:(.text+0x91): undefined reference to `wxApp::wxApp()'
./src/minimal.o:minimal.cpp:(.text+0xf2): undefined reference to `wxAppConsole::ms_appInstance'

...

With a static wxWidgets version and a dynamic build attempt (as we just did), the linker will not find the libwx_*.dll.a-library files (normally located in /mingw/lib), I am not 100% sure what they are needed for, but I assume the linker needs them to know the correct entry points for accessing the DLLs at runtime later on. Anyways, even if you could successfully link an executable, it would complain about missing DLLs if you tried to run it. Just repeat the step Building and configuring wxWidgets and do the dynamic build as described there.

[edit] Fixing the "Program is not a Recognized Executable" Error

When you compile & link a program, the Eclipse run dialog will try to recognize the executable, using one of several parsers. The standard parser does not recognize Windows (wxWidgets) executables, so we're going to change it, before we actually run into this problem:

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)

[edit] Fixing the "Unresolved inclusion" Warnings of Eclipse Indexer

Note: These warnings do not affect successful compilation or execution of your software. They occur because wxWidgets libraries dynamically create the include environment at compile time, and at edit time, Eclipse doesn't know about this environment. Actually, those header files are located at (if you followed the guide) C:\MinGW\include\wx-2.8, and would (to my knowledge) not even reflect the correct behaviour of the included functions, without the compile-time variables. So consider this section to be "eye-candy" more than of any actual use.

In the Project Explorer,

  • select the "sampleMinimal" project

In the Eclipse main menu

  • select "Project" -> "Properties"
  • navigate to "C/C++ General" -> "Paths and Symbols" -> (on the right) "Includes"

In the "Languages" box on the left

  • select GNU C++ (you might want to do the same for GNU C, though it doesn't seem to be necessary as wxWidgets is written in C++)
  • now select "Add..." on the right side of the "Include directories" box

In the "Add directory path" window that pops up,

  • enter C:\MinGW\include\wx-2.8 as "Directory"
  • check "Add to all configurations" (this refers to Build, Release, etc...)
  • select "OK"
  • close the project Properties window by selecting "OK"

This will resolve most of the inclusions and rid you of the annoying warnings, however you will have to do this once for every new project.

[edit] Starting the Executable

In the Eclipse main menu

  • select "Run" -> "Run Configurations..." (Note: this was "Open Run Dialog..." before Ganymede release)

In the "Run Configurations" 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
  • enter some meaningful "Name:" for your new run configuration (e.g. sampleMinimal Release)

For the "Project:"

  • select "Browse"
In the "Project Selection" dialog
  • select "sampleMinimal"
  • select "OK"

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)

Note: If the "Run"-dialog now displays a warning (with a critical symbol) below its caption: "Program is not a recognized executable.", please make sure you have followed the previous step about Fixing the "Program is not a Recognized Executable" Error.

On the bottom right side of the run dialog,

  • select "Run"

This should now launch the "Minimal wxWidgets App". If so, congratulations, you got yourself a working C++ IDE with wxWidgets support. For your own projects, just make sure to set the project properties as described above. And don't forget to distribute the needed DLLs (located in /mingw/bin) with your dynamically linked applications!

[edit] Deleting Unneeded Files

You can now delete the wxWidgets source & build folder wxWidgets-2.8.9 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.9\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] 2009-03-23 15:00 UTC: Release 1, Revision 1 finished

--Lars 15:01, 23 March 2009 (UTC)

Personal tools