Posted by: Josh | January 4, 2010

C++ Windows Development with Eclipse, MinGW and wxWidgets

I’ve recently gotten interested lately in “write once, run everywhere” apps for C++,  where we don’t have the luxury of a Java or similar virtual machine. The idea behind writing in C++ is to remove the dependency of my usual Java runtime environment, and instead use the wxWidgets project to build a C++ project which can be compiled for any architecture it supports (Windows/Linux/Mac). It may also offer performance benefits. In the following guide, I wanted the wxWidgets library statically compiled so that the compilation’s end result is one stand-alone executable which requires nothing else to run.wxwidgets

wxWidgets provides a large set of C++ libraries which will act as an intermediary between my code and operating system-specific calls, such as window handling, networking and disk access. Multi-platform support is then simply a matter of changing the wxWidgets library from one OS’s version to another.

Our ingredients:

Here’s my setup guide.

 

  1. Install MinGW 5.1.6 http://sourceforge.net/projects/mingw/files/
  2. Install MSYS 1.0.11 http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/msys-1.0.11/MSYS-1.0.11.exe/download
  3. Prepend ‘C:\MinGW\bin;C:\msys\1.0\bin;’ as the ‘Path’ Windows environmental variable
  4. Install Eclipse and its CDT (C++) development perspective. At this point, Eclipse should be able to compile non-wxWidget C++ apps.
  5. Install wxWidgets 2.8.10 to C:\MinGW http://www.wxwidgets.org/downloads/
  6. Launch MSYS, and input the following commands (these last two commands may take upwards of ten minutes each to execute, depending on your computer’s performance):
    cd /mingw/wxWidgets-2.8.10
    ./configure –prefix=/mingw –disable-shared
    make && make install
  7. Once completed, should be ready to compile existing wxWidgets C++ projects.
  8. Setting up a new wxWidgets C++ project.
    Project properties -> C/C++ General -> Path and Symbols: set active configuration to ‘Release’
    Project properties -> C/C++ General -> Path and Symbols -> Includes tab. For GNU C++, add directory ‘C:\MinGW\include\wx-2.8’ for all configurations.
    Project properties -> C/C++ General -> Indexer: enable project-specific settings. EDIT 2: ensure “index unused headers as C++ files” is checked.
    Project properties -> C/C++ Build -> Settings -> Tool Settings tab -> GCC C++ Compiler/Directories: add include path
    "C:\MinGW\include\wx-2.8"
    and
    "C:\MinGW\lib\wx\include\msw-ansi-release-static-2.8"
    Project properties -> C/C++ Build -> Settings -> Tool Settings tab -> GCC C++ Linker: set command line pattern
    ${COMMAND} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}
    Project properties -> C/C++ Build -> Settings -> Tool Settings tab -> GCC C++ Linker/Miscellaneous: set Linker flags
    -mthreads  -Wl,–subsystem,windows -mwindows /mingw/wxWidgets-2.8.10/lib/libwx_msw_richtext-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_aui-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_xrc-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_qa-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_html-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_adv-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_msw_core-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_base_xml-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_base_net-2.8.a /mingw/wxWidgets-2.8.10/lib/libwx_base-2.8.a -lwxregex-2.8 -lwxexpat-2.8 -lwxtiff-2.8 -lwxjpeg-2.8 -lwxpng-2.8 -lwxzlib-2.8 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 –lgdi32

    *EDIT*: allow Eclipse auto-complete:
    Project properties –> C/C++ General –> Paths and Symbols –> Library Paths tab, add “C:\MinGW\include\wx-2.8” (“include in all configurations” checked).

  9. Now ready to build and execute.

The above is based on a dynamic compilation of wxWidgets tutorial.

Since this C++ project will be GNU compiler compatible, we should be able to set up a similar development environment in Linux and Mac OS.

I believe you can even cross-compile for an OS that isn’t Windows, from Windows, but haven’t tried it out yet – please leave your experiences in the comment section below!


Responses

  1. Hi Josh,

    I seriously appreciate your work on JSF 2.0 + GAE. Uber-Kudos!

    And… I seriously recommend Qt over wxWidgets.🙂

    Not to undermine wxWidgets, but Qt not only provides native GUI widgets, but also advanced widgets (MVC style) and non-GUI utilities (networking, WebKit, etc.)

    As a bonus, Qt apps work on non-desktop platforms like Maemo, Symbian, and WinCE. The new Qt Mobility project adds mobile features integration too.

    I invite you to my blog at http://qt-mobility.blogspot.com/ for more information about this cool tech.🙂

  2. QT may require license fees to be paid…

  3. @jbear not really. what you said is true years ago but nobody needs to pay any license fee ever since Nokia changed the Qt license to LGPL.

    So Qt is free for use by any application, be it open source, proprietary or commercial ones.

    Nokia actually covers this question in their FAQs and their answer is: The commercial Qt license includes email support, access to upgrades and allows you to develop fully closed source software.

    See: https://fossbazaar.org/content/why-would-you-buy-commercial-qt-license-when-its-lgpl and http://www.qtsoftware.com/about/licensing/frequently-asked-questions#why-would-i-want

  4. Thank you for your description..
    but are you sure that we can use MIGW 32 bit on windows 7 64 bit??
    Im using Eclipse Juno with CDT, but i faild to configure MINGW W64 for Eclipse, Im using windows 7 64 bit..

    THANK YOU

  5. First of all, thanks for your guide. It provides really useful information for usage of wxWidgets with Eclipse.

    I would like to react to Hendy’s comments (I know, it was .. in 2010, but I just bumped into your article today :-D).

    If you statically link to Qt, the application has to be LGPL. This does not happen with wxWidgets, which LPGL licence contains an exception stating that derived works in binary form may be distributed on the user’s own terms.

    This is certainly an advantage of wxWidgets over Qt.

    And I disagree with Hendy who implies that wxWidgets is limited to providing only native GUI widgets. That is a big misunderstanding of what wxWidgets is: http://docs.wxwidgets.org/stable/wx_classesbycat.html (currently stable library, and even was at the time of the discussion when wxWidgets stable was 2.6).

    Eks

  6. Reblogged this on A big picture of Hadi Waseem.

  7. Hola! Podrias informarme cual es el el web host que estas
    llevando? He recargado tu web blog en 3 exploradores de internet radicalmente distintos y no puedo añadir otra cosa que este web
    blog carga rapidamente en todos ellos. ¿Puedes sugerir un buen proveedor de webhost a un monto ceñido?
    Gracias!

  8. I have old and some new applications that use Win32 calls directly. Qt and wxWidgets. Is there a way to use Eclipse for these types of projects? Whether the OS gestapo like it or not, Windows provides lots of built-in functionality that is/can be used and I really don’t want to rework apps..

  9.  No esta pesimo el video-game, me ha otorgado buenos ratos y dee igual modo penosos.

  10. I do agree with @Eks,

    – licensing scheme in wxWidgets is very flexible. Will not find similar scheme in qt, cmiiw…
    – large set of c++ library, ranging from GUI, non GUI, network, filesystem, internet
    – more user contrib library ….
    – large community supported by
    – actively development
    – recently it has very well documentation
    – RAD tools with wxFormBuilder is very powerfull

    How to configure wxWidgets with Windows Netbeans:
    http://yasriady.blogspot.com/2015/08/how-to-setup-wxwidgets-302-with_91.html

    Hopefully, usefull…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: