wxGTK on Mac OSX


Building and installing a usable copy of wxWidgets/wxPython using the GTK toolkit while running on Macintosh OS X has been a project that I have attempted and failed at many times. It had been awhile since my last attempt so I decided to give it ago again using the wxPython release sources and was finally able to successfully get everything to work so I can now run and test programs using wxMac, wxGTK, and wxMSW (with parallels) all at the same time on the same machine without needing to reboot.


While trying to do this I was unable to find very much help or even very much evidence of others who have tried to accomplish this in my searches of the web. The purpose of this article serves a few points.

  1. To say it can be done (on an Intel Mac anyway)
  2. To show how it can be done
  3. Act as a reminder so I remember how to do it next time around

Eight Steps to Completion

Step 1 Installing Needed Tools:

There are some tools that need to be installed prior to working on the build dependencies so install the following items if they are not already on your machine.

Step 2 Installing Dependencies:

In order to build wxGTK on Macintosh OS X there are a number of libraries that need to be installed prior to starting the build so this section will try its best to list out what needs to be installed and how to install it. These instructions will also assume you have installed the above tools at their default locations so adjust accordingly if you have installed them elsewhere.

Unfortunately before I started the build this time I had all of the dependencies already installed so this list may be incomplete as I am going to be going from memories about a year ago. So if I have missed anything please feel free to add it.

Setup build environment

  1. Open up Terminal.app
  2. Copy you profile to a new file to use when building cp ~/.profile ~/GTK_BUILD_ENV

  3. Open ~/GTK_BUILD_ENV in your favorite command line editor
    • vim ~/GTK_BUILD_ENV or nano ~/GTK_BUILD_ENV and add the following lines to the bottom of the file in this order.

    {{{export CC="/usr/bin/gcc -no-cpp-precomp"

export CFLAGS=”-no-cpp-precomp” export CPPFLAGS=”$CFLAGS” export PATH=/opt/local/bin:/sw/bin:/usr/X11R6/bin:$PATH}}}

  1. Update the open shell's environment
    • source ~/GTK_BUILD_ENV

  2. Update Package Systems

{{{sudo port selfupdate fink selfupdate}}}

MacPorts and Fink How To

Start installing the dependencies:

{{{sudo port install gtk2 sudo port install cairo sudo port install pango sudo port install atk sudo port install glib2 sudo port install libgnomeprint sudo port install python2.5}}}

Step 3 Readjusting the Build Environment

Now that the required libraries are installed the build environment needs to readjusted so that the configure scripts for wxWidgets can find them.

  1. Open your profile vim ~/GTK_BUILD_ENV

  2. Add the following new entry to the bottom of the file export LDFLAGS=”-L/opt/local/lib –L/sw/lib”

  3. Modify the following previous entry to match what is shown here export CFLAGS=”-no-cpp-precomp –I/opt/local/include –I/opt/local/include/cairo –I/sw/include”

  4. source ~/GTK_BUILD_ENV

Step 4 Build and Install wxWidgets

For this example I will be using the wxPython sources (http://downloads.sourceforge.net/wxpython/wxPython-src-

I suggest having the BUILD guide available for reference during this step as well (http://wxpython.org/BUILD.html)

Get setup and configure:

  1. Unpackage the source code

    tar xf wxPython-src-

  2. cd wxPython-src-

  3. mkdir gtkbuild && cd gtkbuild

  4. Configure wxWidgets to build wxGTK {{{../configure --prefix=/opt/wx/2.8 \
    • --with-gtk \ --with-gnomeprint \ --without-opengl \ --enable-debug \ --enable-geometry \ --enable-graphics_ctx \ --enable-display \ --disable-debugreport \ --enable-monolithic \ --enable-unicode \ --with-libjpeg=builtin \ --with-libpng=builtin \ --with-libtiff=builtin \ --with-zlib=builtin}}}
  5. If there were any errors that stopped the above command see what it complained about and install it using MacPorts or Fink.

  6. Make a small helper script as described in the BUILD guide

    vim .make  Add this text {{{make $* \

    • && make -C contrib/src/gizmos $* \ && make -C contrib/src/stc $*}}}

  7. chmod +x .make

Do the Build:


NOTE: during some of the final linking I got a number of errors related to undefined symbols for cairo. This was easily fixed by issuing the following command in the shell that you are doing the build in (export LDFLAGS=”$LDFLAGS –lcairo”) and running .make again.


sudo .make install

Part 5 Adjust the Build Environment (Again)


Add the following variables to the end of the file:

{{{export DYLD_LIBRARY_PATH=/opt/wx/2.8/lib export LD_LIBRARY_PATH=/opt/wx/2.8/lib}}}

The CFLAGS need to be adjusted again, these values came from trial and error as it seems that the setup.py script has a hard time finding headers that are in subdirectories as they are when installed using MacPorts.

{{{export CFLAGS= "-no-cpp-precomp -I/opt/local/include -I/sw/include -I/opt/local/include/cairo -I/opt/local/include/gtk-2.0 -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include/pango-1.0 -I/opt/local/lib/gtk-2.0/include -I/opt/local/include/atk-1.0"

export PATH=/opt/wx/2.8/bin:/opt/local/bin:/sw/bin:/usr/X11R6/bin:$PATH}}}

source ~/GTK_BUILD_ENV

Step 6 Build wxPython:

First change directory to the wxPython directory this assumes you are still in the gtkbuild directory from earlier.

cd ../wxPython

When running the following command make sure that you are using the python executable that was installed by using Fink or MacPorts and not the one that is under (/usr/bin or /usr/local/bin).

This is the command that I had to use to it to build correctly on my machine, I had installed python with Fink so if you used MacPorts adjust accordingly.

/sw/bin/python2.5 setup.py build_ext –inplace WXPORT=gtk2 BUILD_GLCANVAS=0 BUILD_OGL=0 WX_CONFIG=/opt/wx/2.8/bin/wx-config

Step 7 Final Configuration:

In order to use the wxPython that was just built some more environment changes are needed so open ~/GTK_BUILD_ENV again and add the following variable to the end of the file where $WXDIR is the full path to the wxPython-src- directory.


Make sure to save the GTK_BUILD_ENV file for future use as you will need to source it in whenever you want to run the GTK version of wxPython that was built. Another note to take care is not to move or delete the wxPython-src- folder as wxPython was installed in there.

Step 8 How to use it:

  1. Start X11.app
  2. In an xterm that is started from X11 setup your environment (source ~/GTK_BUILD_ENV)

  3. Try it out any of your wxPython scripts and see how the work under GTK. For example lets use the demo app that's in wxPython-src- Just make sure to use the same python that you used in Part 6.

{{{cd wxPython-src- /sw/bin/python2.5 demo.py}}}


  1. The wxPython Demo running under wxGTK using Apples X11 window manager


  2. The wxPython Demo running under wxGTK using the Enlightenment e16 window manager


  3. Screenshot with the same program running on all three platforms at the same time (Mac natively, GTK under X11, MSW using Parallels Coherence mode)

    Big Image Click Here



wxGTK on Mac OSX (last edited 2011-03-03 17:31:44 by c-98-246-90-205)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.