Now that Motif is in the public domain, as OpenMotif, it will doubtless become a lot more popular than hitherto with people using it on their own systems. Although I didn't have too many problems installing it on my Red Hat 7.2 Linux system, and getting my first, simple Motif program to work, I would have welcomed a simple 'getting started' guide, so I wrote this document to help other first-time users.
These notes are based on Red Hat Linux 7.2 and RPM. You shouldn't have too many problems with other distributions.
Since Motif requires the X Windows system, you first need to get X working properly. This should be quite straightforward with the current Linux distributions, provided that your graphics hardware is supported.
You now need to download the OpenMotif run-time and OpenMotif developer distributions from the MotifZone. The files you need are openmotif-xxx_ICS.i386.rpm and openmotif-devel-xxx_ICS.i386.rpm, where xxx represents the version number (something like 2.2.2-3).
Log in as root and and install the two downloaded files with rpm -ivh < filename >.For some reason they didn't install properly the first time I tried, gave a couple of error messages and corrupted the RPM database. I removed them with rpm -e openmotif and rpm -e openmotif-devel and fixed the database with rpm -rebuilddb. They then installed correctly. The files ended up in /usr/X11R6/bin etc.
Now you can test the Motif Window Manager (mwm) using the following script:
#!/bin/sh # sample .xinitrc shell script to test mwm # start xterm xterm -geometry 80x40+10+100 -fg black -bg white & # load the Motif Window Manager exec mwm
Cut and paste it into a suitable text editor, save it as .xinitrc in the root directory, and type startx
You should see mwm, with an open terminal window. Type a few commands into the terminal window and check that they work as advertised. Abort mwm (CTRL ALT BS).
Now, save the following C program as push.c:
/* ** push.c ** simple first X/Motif program from "A First Motif ** Program" by Dave Marshall ** (see http://www.cm.cf.ac.uk/Dave/X_lecture/X_lecture.html) */ #include <Xm/Xm.h> #include <Xm/PushB.h> /* Prototype Callback function */ void pushed_fn(Widget , XtPointer , XmPushButtonCallbackStruct *); main(int argc, char **argv) { Widget top_wid, button; XtAppContext app; top_wid = XtVaAppInitialize(&app, "Push", NULL, 0, &argc, argv, NULL, NULL); button = XmCreatePushButton(top_wid, "Push_me", NULL, 0); /* tell Xt to manage button */ XtManageChild(button); /* attach fn to widget */ XtAddCallback(button, XmNactivateCallback, pushed_fn, NULL); XtRealizeWidget(top_wid); /* display widget hierarchy */ XtAppMainLoop(app); /* enter processing loop */ } void pushed_fn(Widget w, XtPointer client_data, XmPushButtonCallbackStruct *cbs) { printf("Don't Push Me!!\n"); }
and compile it with the following incantation: gcc push.c -o push -L/usr/X11R6/lib -lXm -lXt -lX11
If all is well, you should end up with an executable called push. Run mwm again, navigate to the directory where your push program was saved and type ./push to execute it. You should see a button displayed, inviting you to push it. Try it out. If it works, you have successfully created your first Motif application! You can now go ahead and study A First Motif Program in detail.