Using wxWidgets with Cygwin/Mingw32

Compiling with Cygwin/Mingw32 | Further compilation notes | Cross-compilation

Cygwin is a port of gcc to Windows, principally by Cygnus Solutions. Keith Garry Boyce (garp@opustel.com) undertook the initial port of wxWidgets to Cygwin, which involved fixes to compiler headers as well as various wxWidgets changes.

Mingw32, or minimalist Gnu-Win32 (the old name for Cygwin), is a variant of Cygwin without the need for the cygwin.dll overhead and with a smaller distribution footprint.

This page describes how to get wxWidgets and Cygwin or Mingw32 cooperating.

Other sources of information:


wxWidgets 2.x, with Cygwin b20 or Mingw32/gcc 2.95

Here are the steps required:

  1. Retrieve and install the latest beta of Cygwin, or Mingw32.

  2. If using Mingw32, you will need some extra files to use the wxWidgets makefiles. You can find these files in ports/mingw32/extra.zip on the FastPic Systems ftp site. These should be extracted to the Mingw32 directory.

    If using Mingw32 2.95 or below with wxWidgets 2.1 or above, you must hand-patch in Mingw32-gcc295.patches (in the top-level of the wxWidgets 2 installation). Mingw32 2.95.2 and above does not need patching.

  3. Modify the file cygnus.bat (or mingw32.bat) to set up appropriate variables, if necessary mounting drives. Note that these batch files are found in wx/install for wxWidgets 1.68, and wx/src for wxWidgets 2.

  4. Configuring for Mingw32 or Cygwin.
    • If using wxWidgets 2.1 or above, edit wx/src/makeg95.env and set the MINGW32 variable at the top of the file to either 1 (you have Mingw32) or 0 (you have Cygwin). Note: Cygwin 1.1.0 and above may need MINGW32 set to 1 to compile properly.
    • If using an older version of wxWidgets 2, edit wx/src/makeg95.env and search for MINGW32. Take note of the comments for adjusting settings to suit Cygwin or Mingw32. Basically, this is just a case of adding the __MINGW32__ symbol to OPTIONS for Mingw32, or removing it for Cygnus Cygwin. For Mingw32/EGCS, add both __MINGW32__ and __EGCS__.

  5. Use the makefile.g95 files for compiling wxWidgets and samples, e.g.:
      > cd c:\wx\src\msw
      > make -f makefile.g95
      > cd c:\wx\samples\minimal
      > make -f makefile.g95
    

  6. Use the 'strip' command to reduce executable size.

  7. With Cygwin, you can invoke gdb --nw myfile.exe to debug an executable. There is an optional gdb binary for Mingw32.

  8. If using GnuWin32 b18, you will need to copy windres.exe from e.g. the Mingw32 distribution, to a directory in your path.

All targets have 'clean' targets to allow removal of object files and other intermediate compiler files.

Gotchas:

For instructions on using earlier versions of wxWidgets and Cygwin, please see the old Cygwin page.


Further compilation notes

Here's a note from Mumit Khan on using COM with Mingw32. wxWidgets uses some COM (for example for drag and drop, clipboard and wxAutomationObject) and it's not yet known whether it's affected by this.


Date: Thu, 16 Mar 2000 08:42:18 -0600 (CST)
From: Mumit Khan 
To: Mingw32 discussion list at eGroups 
Mailing-List: contact mingw32-owner@egroups.com
Reply-To: mingw32@egroups.com
Subject: [mingw] [ANN] libstdc++.a for COM/OLE/-fvtable thunks

COM/OLE etc code needs to be compiled with -fvtable-thunks, and that
causes problems with the supplied C++ runtime library if you're deriving
from any one of the standard classes supplied. I've uploaded libstdc++.a
compiled with -fvtable-thunks that you can link with for COM code.

Both CRTDLL and MSVCRT versions are on the ftp site:

ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/libstdc++vthunk/

Unzip the appropriate distribution somewhere, say c:/gcc-2.95.2/COM, and
use -I and -L flags:
  
  $ c++ -fvtable-thunks -Ic:/gcc-2.95.2/COM/include foo.c
  $ c++ -fvtable-thunks -Lc:/gcc-2.95.2/COM/lib -o foo foo.o

Regards,
Mumit


We have a hard time keeping up with all the combinations and versions of Cygwin and Mingw32. Here's an email from a user of a Cygwin/Mingw32 combination, with wxWidgets 2.1.11. (Note that more recent version of wxWidgets compile with Mingw32 with less trouble).

Date: Mon, 08 Nov 1999 21:44:47 +0200
From: alexander smishlajev 
To: wxwin-developers@wx.dent.med.uni-muenchen.de
Subject: wxWidgets compilation problems (win32, gcc 2.95)
Reply-To: wxwin-developers@wx.dent.med.uni-muenchen.de

hello!

i am trying to compile today's snapshot of wxWidgets using cygwin32 (gcc
2.95) in mingw32 build mode.  the following things caused problems for
me:

- include/wx/msw/setup0.h defines wxUSE_NORLANDER_HEADERS.  i do not
know what they are and probably do not have any.  (if
wxUSE_NORLANDER_HEADERS is defined, _stdcall is used for CASTWNDPROC,
and i did not found _stdcall anywhere in my headers.)

- CASTWNDPROC should be defined as WNDPROC in include/wx/msw/private.h

- wxFONTENUMPROC should be defined as FONTENUMEXPROC in
src/msw/fontenum.cpp

- undefined BFFM_* constants in src/msw/dirdlg.cpp

- ${ADVANCEDOBJS} should not be added to ${OBJECTS} in
src/msw/makefile.g95

having said that, i found the Win32 API library by Anders Norlander at
http:
will do the trick (at least missing things are defined there), but i
cannot test it today.

best wishes,
alex.


Cross-compilation

From Bernard Dautrevaux:

I've received several requests like this one; the best starting point (at least to my knowledge) is Mummit Khan's web page:

www.xraylith.wisc.edu/~khan/software/gnu-win32/

You'll find a host of links to various gnuwin32/mingw32 resources.

At:

www.xraylith.wisc.edu/~khan/software/gnu-win32/mingw-cross-howto.txt

you'll find instructions on building agcs as a cross-compiler from an UNIX system (usually Linux) for mingw32. I follow these instructions, and all went smoothly; this is rare enough to deserve a mention :-) For building a mingw32 toolset (for generating true Windows applications) look under the heading 'Building CROSS Mingw32 tools'.

There are precompiled binaries for Linux, but I do not remember exactly where. Probably Mummit can help people needing these and not able to build them by themselves. He is always very responsive to questions, but please do not overload him...

See also the technical note Cross-compiling Windows applications on Linux.