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 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:
- A Windows environment (in my case, Windows 7 Pro 64-bit)
- Eclipse 3.5 “Ganymede” with CDT Plug-in
- MinGW 5.1.6
- MSYS 1.0.11
- wxWidgets 2.8.10 source
Here’s my setup guide.
- Install MinGW 5.1.6 http://sourceforge.net/projects/mingw/files/
- Install MSYS 1.0.11 http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/msys-1.0.11/MSYS-1.0.11.exe/download
- Prepend ‘C:\MinGW\bin;C:\msys\1.0\bin;’ as the ‘Path’ Windows environmental variable
- Install Eclipse and its CDT (C++) development perspective. At this point, Eclipse should be able to compile non-wxWidget C++ apps.
- Install wxWidgets 2.8.10 to C:\MinGW http://www.wxwidgets.org/downloads/
- 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 - Once completed, should be ready to compile existing wxWidgets C++ projects.
- 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). - 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!
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. 🙂
By: Hendy Irawan on February 11, 2010
at 11:54 am
QT may require license fees to be paid…
By: jbear on March 21, 2010
at 3:13 am
@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
By: Hendy Irawan on March 21, 2010
at 8:21 am
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
By: bassam on October 31, 2012
at 4:02 am
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
By: Eks on May 23, 2013
at 8:36 am
Reblogged this on A big picture of Hadi Waseem.
By: Musa on February 1, 2014
at 12:15 am
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!
By: mucha informacion on October 2, 2014
at 12:34 pm
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..
By: Shauno on December 6, 2014
at 6:25 pm
No esta pesimo el video-game, me ha otorgado buenos ratos y dee igual modo penosos.
By: trucos juegos facebook on April 30, 2015
at 2:53 am
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…
By: Dedy Yasriady on August 15, 2015
at 4:44 pm
Skype has established its web-dependent buyer beta towards the
world, following establishing it largely in the U.S.
and You.K. before this month. Skype for Website also now can handle Linux and Chromebook for immediate messaging connection (no video and voice nevertheless, individuals demand
a connect-in installing).
The expansion from the beta brings help for an extended listing of different languages to help
bolster that worldwide usability
By: Jayne on July 10, 2017
at 5:04 am