Next: Explanation of the Up: Introduction Previous: The General Plan

Your first program

To get a feel for all of this, here is your first program. Go ahead and type it in to a file called "first.c":


        #include <X11/Intrinsic.h>
        #include <Xm/Xm.h>
        #include <Xm/Label.h>

        main(int argc, char *argv[])
        {
          Widget toplevel, msg;
          Arg al[10];
          int ac;

          toplevel=XtInitialize(argv[0],"",NULL,0,&argc,argv);
          ac=0;
          XtSetArg(al[ac],XmNlabelString,
                XmStringCreate("hello",XmSTRING_DEFAULT_CHARSET)); ac++;
          msg=XtCreateManagedWidget("msg",xmLabelWidgetClass,toplevel,al,ac);
          XtRealizeWidget(toplevel);
          XtMainLoop();
        }

It looks like a mess, I know, but that is about the simplest Motif program you can write. To compile it type:


        cc -o first first.c -lXm -lXt -lX11

[Eos isn't quite that far along yet. On Eos you need to type:

cc -o first first.c -L/usr/local/lib/motif -L/usr/local/lib/UDW -lXm -lXt
-lUDWX11 -I/usr/local/include/motif             ]

Obviously you'll want to create a make file. [Or better yet (if you're on Eos), grab the makefile in ncsu/mb_info/young and modify it as needed.]

It may take three to five minutes to compile. If you run out of disk space, delete some stuff and start over (motif applications are BIG). [If you continue to have space problems, compile the executable to /tmp.] To run it, type "first". It will take up to 30 seconds, but you should eventually see a small window containing the word "hello". You can resize it, iconify it, etc.

Play around with "first" for awhile, and then go to mt2. In that tutorial I'll explain what all of the stuff in first.c does.


morbe@enstb.enst-bretagne.fr