Introduction to wxWidgets

wxWidgets is a leightweight GUI toolkit that is primarily targeted for C++ but is also available for other languages including Python. It gives applications a truly native look by using each platform's native API. wxWidgets is completely open source using the wxWidgets licence which is a more liberal version of the LGPL (allowing distribution without the source code). It is very actively developed and maintained and has good support for all common programming environments. The source code is available on the project's Github page.

To get started, install the required dependencies

sudo apt install libwxgtk3.0-gtk3-dev

After the installation, follow the official Hello World Example. Save your code to hello_wx.cpp To compile the example, type

clang++ hello_wx.cpp `wx-config --cxxflags --libs` -o hello_wx

Start your first GUI application by typing ./hello_wx.

wxWidgets hello world application

Compile with GNU Make

wxWidgets files can, of course, also be compiled with GNU Make. Use the source below as an example

# Sample Makefile for wx applications
WX_CONFIG := wx-config
WX_CXXFLAGS := $(shell $(WX_CONFIG) --cxxflags)
WX_LIBS := $(shell $(WX_CONFIG) --libs)

APPLICATION := hello_wx  # adjust name to your desired application name
OBJECTS := hello_wx.o app.o  # enter the .o files or generate this list

all: $(APPLICATION)

$(APPLICATION): $(OBJECTS)
	$(CXX) -o $@ $(OBJECTS) $(LDFLAGS) $(WX_LIBS) $(LIBS)

$(OBJECTS): %.o: %.cpp
	$(CXX) -c -o $@ $(WX_CXXFLAGS) $(CXXFLAGS) $<

.PHONY: clean
clean:
	find . -name '*~' -o -name '*.o' -o -name $(APPLICATION) | xargs rm

Download the above template Makefile.