wxWidgets 101: A Minimal Hello World Example for Mac

Lynn Zheng
2 min readJun 8, 2019

--

wxWidgets is the tool that I will be using in my 2019 Summer internship to develop Apps for PC, Mac, and Linux. To familiarize myself with this tool, I started with the minimal example of a Hello World App.

The best way I found to install wxWidgets on Mac is to use Homebrew. You can download it here if you haven’t already.

In the Terminal, run this command.

brew install wxwidgets

If the installation is successful, running which wx-config should bring up a line like /usr/local/bin/wx-config .

To build our Hello World App, we need two files: hello.h and hello.cpp.

hello.h holds our header declarations and has the following content.

#ifndef __HELLO_H
#define __HELLO_H
class HelloWorldApp : public wxApp {
public:
virtual bool OnInit();
};
DECLARE_APP(HelloWorldApp)#endif

hello.c holds our class definition and has the following content.

#include "wx/wx.h"
#include "wx/wxprec.h"
#include "hello.h"
IMPLEMENT_APP(HelloWorldApp)bool HelloWorldApp::OnInit() {
wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
frame->CreateStatusBar();
frame->SetStatusText(_T("Hello World"));
frame->Show(true);
SetTopWindow(frame);
return true;
}

In the Terminal, we compile hello.cpp as follows. This produces a binary with the name hello .

g++ hello.cpp `wx-config --libs --cxxflags` -o hello

Great work, we’ve just created our first wxWidgets App! We can run it as ./hello .

I’ve promised you a minimal tutorial, so this is it for now. Thanks for reading!

Reference:

https://docs.wxwidgets.org/stable/overview_helloworld.html

--

--