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.9.0 most recent packages as of 2010-06-14 most recent packages as of 2010-06-14
Status: partially out of date


Related Articles
HowTo: Install MSYS and MinGW for use with Eclipse CDT
Building Xerces-C++ XML Parser for EMMe
Building Boost C++ Libraries for EMMe
Credits: Eclipse, CDT & MingW & MSYS Setup Guide
older: 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 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.

Note that this article uses MSYS. Using MSYS is neither necessary nor the easiest way to build or use wxWidgets on Windows

Preparatory Steps

As software versions may change over time, <version> will be used in the guide as a placeholder for the current version number as listed in the Intended for Software Versions section. For example, if jre-6u20-windows-i586.exe is the current software version, then the guide may tell you to

  • execute jre-<version>-windows-i586.exe

Prerequisites & Disk Space

You will need a file archiving software capable of uncompressing lzma, gz and tar files.

One free software solution is 7-zip (windows executable) direct link.

The whole installation comprising MinGW, MSYS, Eclipse Galileo & wxWidgets (with wxWidgets samples, but without setup or source files) takes up about 360MB on your hard disk. During the installation process you will need about 1.5GB of free hard disk space.


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:

MSYS MinGW group (1) - ca. 8MB
- all versions according to MSYS installation guide
MinGW MinGW group (1) - ca. 17MB
- all versions according to MinGW installation guide
jre-6u20-windows-i586.exe Java SE Runtime Environment 6u20 (2), see also (2a) - 15.5MB
eclipse-cpp-galileo-SR2-win32.zip Eclipse Galileo (3) - 80MB
wxWidgets-2.8.11.tar.bz2 (4)  2.8.11 direct link (4a) - 13.4MB
 OR
wxWidgets-2.9.0.tar.bz2 (4)  2.9.0 direct link (4b) - 14.8MB

Note that trouble finding libraries at compilation time later in this guide may be attributable to the use of older MSYS versions (Installer).

MSYS Installation

Please follow the steps described in HowTo: Install MSYS and MinGW for use with Eclipse CDT, section MSYS Installation.

Note: This guide assumes that you have installed MSYS to the folder c:\msys\1.0\

MinGW Installation

Please follow the steps described in HowTo: Install MSYS and MinGW for use with Eclipse CDT, section MinGW Installation.

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

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-6u20-windows-i586.exe

On the "Welcome to Java"-window

  • select "Accept >"

This will start the installation process. When it is done

  • select "Finish"

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-galileo-SR2-win32.zip (main eclipse folder)
  • move 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"

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)

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 "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.

  • configure your project to use the Windows PE Binary Parser
  • in the Project Explorer on the left, select the configTest project (alternatively, have focus to the source code editor for configTest.cpp - just don't have focus on 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...

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.

Building and Configuring wxWidgets

  • close Eclipse (if still open)
  • extract wxWidgets-<version>.tar.bz2 (unzip, then untar)
  • move the contained folder wxWidgets-<version> to "C:\mingw" (so that it becomes C:\mingw\wxWidgets-<version>)
  • 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-<version>
mkdir build-release
cd build-release
../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 to a couple of hours.

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.

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.

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"

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 "+")

Tool Settings (Compiler and Linker)

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`
  • with wxwidgets 2.8.10 (and maybe earlier) the following "Linker flags" are sufficient
`wx-config --static=no --libs`

If you want to avoid running into linker troubles later on, this is the time to decide what you want to do with the auto-import functionality of the linker.

If you want to turn it on by default, you will have to add this linker flag:

-Wl,--enable-auto-import


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!

Notes:

  • 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"
  • the -mwindows linker flag is to not open a dos window upon program execution because we are developing a graphical application

Build Steps

Optional build step:

Build Artifact

Binary Parsers

The "Run Configurations" environment of Eclipse uses one of several binary parsers to recognize executables in the project. The default setting for the Linux GCC toolchain is the "Elf Parser", which will fail to recognize your executables in this environment. Therefore:

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


Known problems:

  • if you have another msys distribution installed (e.g. WinAVR) it may interfere with your just installed one. In the eclipse console you'll read something like: "/bin/sh: wx-config: command not found". You can change that by deleting the path entry for the previous installation (e.g. C:\WinAVR-20090313\utils\bin).

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.


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 you did change the binary parser to PE Windows Parser, you should also be able to select the "C/C++ Application" via the "Search Project..." button. Otherwise, the "Run"-dialog will now display a warning (with a critical symbol) below its caption: "Program is not a recognized executable.".

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!

Deleting Unneeded Files

You can now delete the wxWidgets source & build folder wxWidgets-<version> 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-<version>\samples), in case you want to experiment some more with these.


Support for other Tools/Libraries

If you want to have any additional tools or library support, have a look at one of these guides, all of them written for the Eclipse-MSYS-MinGW environment (EMMe):

Generic Eclipse (Project) Settings & Troubleshooting

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

Fixing the "Unresolved inclusion" Warnings of Eclipse Indexer

Note: In this section, <major-version> is to be replaced with the first two levels of the wxWidgets version number (i.e. 2.8.9 -> <major-version> = 2.8)

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-<major-version>, 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-<major-version> as "Directory"
  • check "Add to all configurations" (this refers to Build, Release, etc...)
  • select "OK"
  • navigate to "C/C++ General" -> Indexer

In the "Indexer" box on the left

  • enable the "Enable project specific settings" checkbox
  • close the project Properties window by selecting "OK"

In the window that pops up:

Paths and Symbols

Changes to the include search paths or defined symbols will not be reflected
in the index until it is rebuilt. Do you wish to rebuild it now?
  • confirm with "Yes"

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.

Note: If you want to get rid of all unresolved inclusions, right click your project and select "Index" -> "Search for Unresolved Inclusions". This will show you all missing header files. In almost all cases it will be "setup.h". So copy the setup.h (that depends on your wxWidgets build) stored along with your compiled lib into directory include/wx. If setup.h is missing, you will have auto-completion for most wxWidgets classes and for some such as wxRegEx you won't.

Build Configurations

Some Notes on the Debug (Default) Build 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

Changing the Build Configuration

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

  • select the desired project 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 (project name)" 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)

If you build the project via "Project" -> "Build Project" now, your release executable will be located in the Eclipse workspace subfolder "(project name)\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)!

Stripping Debug Overhead from Executables

In the Eclipse main menu

  • select "Project" -> "Properties"

In the "Properties for (project name)" window

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

In the expanded C/C++ Build section

  • select "Settings"

In the "Settings" on the right,

  • select the "Build Artifact" tab and make a note of/copy the "Artifact name"
  • select the "Build Steps" tab

Under Post-build steps

  • as "Command:" type
strip <artifact name>.exe

(e.g. strip configTest.exe)

  • select "OK" to close Project Properties

After each build, Eclipse will now call strip to remove debug information from your executable.

Optional: Manual Steps

You can strip the debug information from the file manually 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


Build Artifact

Eclipse (at least since Galileo) will no longer automatically clean your .exe-File with Project -> Clean.... This will result in make refusing to re-build the project unless you change something in the code ("make: Nothing to be done for `all'.").

In order to have the executable removed, you need to tell Eclipse it's file extension:

  • select your project in the Project Explorer

In the Eclipse main menu

  • select "Project" -> "Properties"

In the "Properties for (project name)" window

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

In the expanded C/C++ Build section

  • select "Settings"

In the "Settings" on the right,

  • select the "Build Artifact" tab

For "Artifact extension", type "exe"

  • select the "Build Steps" tab
  • select "OK" to close Project Properties


Fixing the "Program is not a Recognized Executable" Error

When you compile & link a program, the Eclipse run feature 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)

Linker option --enable-auto-import

Please read this article on the --enable-auto-import linker option for a good understanding of why you might be getting the following (or similar) warning, and decide whether you want to --enable-auto-import by default.

Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
 from auto-imported DLLs.)

Enabling auto-import:

  • in g++, the command line option to actively enable auto-import is
-Wl,--enable-auto-import

(same option to be used for Eclipse linker call!)

  • if the linker is called separately, the option should be just (not tested):
--enable-auto-import

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)


2010-06-14 15:00 UTC: Release 2, Revision 0 finished

--Lars 14:57, 14 June 2010 (UTC)