1.2. Your first Motif Program   

The best way to understand how to use any programming library is by trying some simple examples. A collection of example programs that introduces some of the widgets in the Motif widget set can be found in the directory


You can now create your first Motif program (see later to retrieve it):


* xmhello.c - simple program to put up a banner on the display
* Header files required for all Toolkit programs
#include <X11/Intrinsic.h> /* Intrinsics definitions */
#include <Xm/Xm.h> /* Standard Motif definitions */
* Public header file for widgets actually used in this file.
#include <Xm/Label.h> /* Motif Label Widget */
main(argc, argv)
int argc;
char **argv;
XtAppContext app_context;
Widget topLevel, hello;
topLevel = XtVaAppInitialize(
&app_context, /* Application context */
"XMhello", /* Application class */
NULL, 0, /* command line option list */
&argc, argv, /* command line args */
NULL, /* for missing app-defaults file */
NULL); /* terminate varargs list */
hello = XtVaCreateManagedWidget(
"hello", /* arbitrary widget name */
xmLabelWidgetClass, /* widget class from Label.h */
topLevel, /* parent widget */
NULL); /* terminate varargs list */
* Create windows for widgets and map them.
* Loop for events.

You will also need to have an Imakefile:

    #include <Motif.tmpl>

FILE = xmhello
SRCS = $(FILE).c
OBJS = $(FILE).o

The alternative would be for you to grab the source code (via ) and compile it on your machine.
Imakefile xmhello.c

After retrieving and saving the code plus Imakefile, you should be able to type:
xmkmf -a ; make FILE=xmhello
This will produce the executable called xmhello.

It is possible to execute a (different) xmhello program and display it on your screen. To run it, your system must be running X and the server control is set to xhost . Also it will not work if you are using a proxy server or you are running your browser on a machine different from the one you are displaying it on. Many example programs are available