From WxWiki
Jump to navigation Jump to search

Using Eclipse with pre-built wxWidgets libraries

Eclipse is an open, extensible IDE not targeted for any specific language or environment. Supported languages can be configured and installed using a plugin framework. The main Eclipse download comes with only the plugin for Java development, but I will explain here the steps required to configure Eclipse as a C++ development platform, and to setup a project for a wxWidgets application.

Note that even if the eclipse IDE is nice to use and has many features it is written in Java and therefore it eats your RAM! On my win2k/XP system it usually needs > 100 MB of RAM. As I have only 256 MB of RAM my system is hard to use as it access my HD each time I switch tasks. For that matter, if you'd like an IDE which is made with wxWidgets itself and doesn't eat that much RAM, be sure to check out Code::Blocks IDE or Chinook IDE.

Here you can choose one of the following installation methods:

Installing manually

  • Download Eclipse for your OS from . There're quite a few different downloads, the one you want is labeled as Eclipse SDK. The exact name for the linux version filename is, this of course will change depending on your OS and version, but will give you an idea of the file you have to download. It's a 80 MB download or so, so be patient until it finishes.
  • Eclipse doesn't require any special installation. Just unpack the file to a folder, and start the executable (unsurprisingly named "eclipse"). It will ask you for a directory to save projects in, and then will show some nice tutorials. Read them if you want(Strongly Suggested.), and when you're finished close them, you will be at the main Eclipse window.
  • At first, eclipse only includes Java support. Since we want to use wxWidgets, we need C++ support. Go to "Help->Software Updates->Find and Install", tell Eclipse to look for new features. Click on "New remote site" and fill in the URL of the CDT (C/C++ Development Tools for Eclipse). The URL can be found on the download section of the CDT (, and in my case it is Once it's done, the option for downloading CDT will appear. Check it, answer the next questions and wait until all is downloaded and installed. The installer will ask you to restart Eclipse, so do it.
  • Now we have C++ support for Eclipse installed. Before proceeding, check that it actually works. Try creating a standard C/C++ project with a "Hello world!" or something like that. Keep in mind that, since Eclipse is only an IDE, you'll need a C++ compiler and libraries. I do all my development with gcc, make, etc., which are standard in Linux, and can be installed in Windows using MINGW. Check that all relevant binaries are in PATH (Important for Windows users).

Installing on *Ubuntu

On *Ubuntu you can install the package eclipse-cdt, i.e. use samething like

sudo apt-get install eclipse-cdt

If you do not have installed gcc already, install the package build-essential, i.e. use something like

sudo apt-get install build-essential

If you do not have installed wxwidgets, install the packages libwxgtk2.8-dev and libwxgtk2.8-dbg, i.e. use something like

sudo apt-get install libwxgtk2.8-dev libwxgtk2.8-dbg

See also Installing_and_configuring_under_Ubuntu.

Testing Your Configuration

One way to test if everything can be set up right is to import a sample project from the wxWidgets build files found in <wxWidgets root>/samples/<proj name>.

  • Go: File -> Import -> General -> File System and then navigate to the path of the project and import the files.
  • Note that projects need the image file, sample.xpm, in order to compile. It is located in <wxWidgets root>/samples so you will also need to import that and then change the path that appears in the .cpp files.


Eclipse CDT <3.0.0

Now it's time to create a project with wxWidgets in mind. Create a new, managed C++ project in the folder of your choice. Add a new file to the project (one of the wxWidgets samples is a good choice), and go to project properties. Select C/C++ Build and, on the right, GCC C++ Compiler, a field called "All options" will appear. Open a console, type the command "wx-config --cxxflags", copy the output and append it to this field. Do the same for the command "wx-config --libs" and the field "All options" that appear when "GCC C++ linker" is selected. As far as I know, the command wx-config is only available on Linux wxWidgets installations, so if you use Windows you'll have to guess the right options. The easiest way is to look inside a working makefile and use the options that appear there.

Eclipse CDT >3.0.0 and <4.0.0

The "All Options" Textfield is no longer editable in Eclipse CDT 3.0.0 instead you have to follow these instructions:

  • Create a new, managed C++ project.
  • Add a new file to the project (i.e. "main.cpp" ), and go to project properties.
  • Select "C/C++ Build" and then "Settings".
  • Select "GCC C++ Compiler" and the underlying "Miscellaneous" tab. Append "`wx-config --cxxflags`" to the "Other flags" edit field. Don't forget the `backquotes`!
  • Select "GCC C++ Linker" and again the underlying "Miscellaneous" tab. Append "`wx-config --libs`" to the "Linker flags" edit field. Don't forget the `backquotes`!
  • Optional: Select "GCC C Compiler" and the underlying "Miscellaneous" tab. Append "`wx-config --cflags`" to the "Other flags" edit field. You are not likely to need this

You may have to add /usr/local/lib to your LD_LIBRARY_PATH in the C/C++ Build->Environment tab (but you shouldn't since wx-config's cxxflags do that for you)

Some hints:

  • If the backquotes do not work (wx-config file of folder has not been found) append the corresponding output of the wx-config command directly to the "Other flags" and "Linker flags" edit fields.
  • If linking fails with hundreds of "undefined reference to ...", move ${FLAGS} to the end of the line in the "Linker flags" edit field.

Eclipse CDT >4.0.0

For CDT 4.0 and up "Managed Make C++ project" has been replaced with "Executable".

  • To create a new project you can go File -> New -> Project -> C++ Project -> Executable
  • By default, the project will be managed. Manageability can be set with the check box, "Generate Makefiles Automatically", under the project properties dialog -> C/C++ Build page -> Builder Settings tab.

That's it, now you should have code completion for wxWidgets and you should be able to compile the project.


On Windows, Eclipse can work with the MinGW compiler. See also: Compiling wxWidgets with MinGW. Using the MSVC compiler might also be possible (and yield smaller executables), but that's not yet documented here.

  • Build a Hello World app by following the instructions in the VERY GOOD Help Contents of Eclipse (Menu->Help).
      (I will try to use the Managed make c++ Project because I don't want to edit makefiles by hand!)
      Play around with MinGW's API support...
      Did you notice that you can reduce the size of an executable to ~ 5 KB by using the strip application coming with MinGW!?
      To also test some specific win32 API I included <windows.h> and did a MessageBox(0,"Hello World", ":)", MB_OK);
      NOTE: You wonder why there is a cmd shell window even if you use WinMain() instead of main()?
            Add '-mwindows' to Properties->C/C++ Build->GCC C++ Linker->Miscellaneous
  • Then, after you have played around with MinGW...
  • Install wxWidgets following instructions in wx\INSTALL-MSW.txt section MinGW ;)
      NOTE: in wxWidgets 2.5.3 Me (and others) recongized that it does not work with the make.exe supported in c:\msys\1.0\bin
            If you want to use make directly (as I did) you MUST USE c:\MinGW\bin\mingw32-make.exe and ALSO REMOVE c:\msys\1.0\bin from PATH!!
            (Thesz: or, simply, use 'make --win32 <other parameters>')
            then goto wx\build\msw\ and do a 
                 make -f makefile.gcc BUILD=debug RUNTIME_LIBS=static
                 make -f makefile.gcc BUILD=release RUNTIME_LIBS=static
                 (it might want you to create some subfolders...)
      After houres of compiling...
  • Try to compile minimal sample with make -f makefile.gcc BUILD=release RUNTIME_LIBS=static (worked for me)
  • Finally:

1. I created a new managed make c++ project in eclipse,

2. Added the .cpp file of minimal wxWidgets sample,

3. Copied most of the g++ compile- and linker-options i get in a console using

make -f makefile.gcc BUILD=release RUNTIME_LIBS=static

to my project's preferences (except the one -Dlsubsystem,windows?? linker thing i didn't understand (and didn't really care, too)) (Of course I had to adapt the path of the includes...)

4. Compiled! SUCCESS! Linked ! SUCCESS!

For an article on using Eclipse on Windows, see the C++ GUI Programming on Windows 2000/XP article by Brian Lee.

Additional Resources

An alternate how-to is available at

Building wxWidgets libraries with Eclipse

Eclipse can build the wxGTK-2.6.3 libraries. I've built it on Debian 3.1, Suse 10.0 and Ubuntu 5.10.

I did it (and it can be done) in exactly the way that you'd expect and want: as a real Eclipse project. That is, it uses Managed Makefiles, not Standard Makefiles, so the user can add, remove and browse individual source files, compiler options, linker options and Eclipse configurations. To reiterate, this isn't just a call-out to the existing makefile or building a wxWidgets project using pre-built wxWidget libraries. This is building the entire wxWidgets source code to produce the .a and .so files that make up wxWidgets itself.

It supports both a Debug and a Release configuration.

I hope to improve it to a point where it can be integrated with the wxWidgets bakefile and source (if that is what is feasible and appropriate). It still has some caveats which may be my fault or Eclipse's shortcomings.

Debugging works but gdb (which is the debugging engine for Eclipse CDT) throws some harmless but annoying warnings. A different version of gdb may fix these glitches or a new Eclipse CDT version.

Heikki Toivonen of the Open Source Applications Foundation has been kind enough to post my downloadable set of files along with his experiences of installing them on Ubuntu at this URL:

wxWidgets in Eclipse on Ubuntu

Feel free to e-mail me at [email protected] with any questions or comments.