What are the "serious" libraries?

Joe Nelson joe at begriffs.com
Tue Apr 7 03:50:53 UTC 2020

> > Can you also recommend a GUI library that has widgets like buttons
> > and text fields for more desktop-y apps?

David Klann wrote:
> The obvious candidates here are:
>  - Qt (sometimes pronounced "cute"): https://www.qt.io/developers
>  - GTK: https://www.gtk.org/docs/
>  - WxWidgets: https://www.wxwidgets.org/

I spent some time tonight comparing these and some others. There are
plenty of libraries for C++ it seems, and the only mainstream one for C
is GTK+. That thing is a bit of a beast, and reportedly its API isn't
very stable across releases.

One thought I had was to combine a C application with a scripting
language like Tcl or Lua to handle the GUI, using Tk or a Lua wrapper
for one of the C++ frameworks.

However there's another option, a truly oldskool library called Motif.
It might just fit the bill, if you don't mind a grey rectangular
interface that looks like it's from 1985 (I don't).

The Definitive Guides To The X Window System, Vol 6, Motif Programming
Manual says this by way of introduction:

	So why motif? Because it remains what it has long been: the common
	native windowing toolkit for all the UNIX platforms, fully supported
	by all the major operating system vendors. It is still the only
	truly industrial strength toolkit capable of supporting large scale
	and long term projects. Everything else is tainted: it isn't ready
	or fully functionally complete, or the functional specification
	changes in a non-backwards-compatible manner per release, or there
	are performance issues. Perhaps it doesn't truly port across UNIX
	systems, or it isn't fully ICCCM compliant with software written in
	any other toolkit on the desktop, or there are political battles as
	various groups try to control the specification for their own
	purposes. Indeed it may matter very much whose version of the
	toolkit you have managed to acquire, or if the toolkit is open
	sourced so you have no idea who is going to stick their untrusted
	fingers into it at any time. So many problems with each choice you
	make. With motif, you know where you are: its stable, its robust,
	its professionally supported, and it all works.

I was a little worried about Mac support, but I just got the hello world
example from that book to work. Mac has an X11 port called XQuartz. I
also installed the openmotif package from macports, and used the
following Makefile settings (couldn't find a pkg-config definition, but
it may be on my system somewhere).

CFLAGS = -std=c99 -Wall -Wextra -pedantic -I/opt/local/include
LDFLAGS = -L/opt/local/lib -lXt -lXm

The hello world source file is attached inline to this message so you
can try it yourself. :)
-------------- next part --------------
#include <stdio.h>
#include <Xm/PushB.h>

void button_pushed(Widget widget, XtPointer client_data, XtPointer call_data)
	printf("Hello Yourself!\n");

int main(int argc, char *argv[])
	Widget toplevel, button;
	XtAppContext app;
	XmString label;
	Arg args[2];

	XtSetLanguageProc (NULL, NULL, NULL);
	toplevel = XtVaOpenApplication(
			&app, "Hello", NULL, 0, &argc, argv,
			NULL,sessionShellWidgetClass, NULL);
	label = XmStringCreateLocalized("Push here to say hello");
	XtSetArg(args[0], XmNlabelString, label);

	button = XmCreatePushButton (toplevel, "pushme", args, 1);
	XmStringFree (label);
	XtAddCallback (button, XmNactivateCallback, button_pushed, NULL);

	XtManageChild (button);
	XtRealizeWidget (toplevel);
	XtAppMainLoop (app);
	return 0;

More information about the Friends mailing list