NEWBIE - How to compile program using Motif libraries ? - Motif

This is a discussion on NEWBIE - How to compile program using Motif libraries ? - Motif ; Hi, I am just starting out on X11 programming with Motif. I am using RedHat Linux 9 with OpenMotif. I tried to compile a program with the following command line - gcc -I /usr/X11R6/LessTif/Motif1.2/include -L /usr/X11R6/LessTif/Motif1.2/lib push2.c -o push -lX11 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: NEWBIE - How to compile program using Motif libraries ?

  1. NEWBIE - How to compile program using Motif libraries ?

    Hi,

    I am just starting out on X11 programming with Motif.
    I am using RedHat Linux 9 with OpenMotif.

    I tried to compile a program with the following command line -

    gcc -I /usr/X11R6/LessTif/Motif1.2/include -L
    /usr/X11R6/LessTif/Motif1.2/lib push2.c -o push -lX11

    The program itself started out like -

    --------------------------------------------------------------------
    #include
    #include

    /* 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");
    }
    ---------------------------------------------------------------

    I am getting the following compile error -

    push2.c: In function `main':
    push2.c:25: warning: passing arg 3 of `XtAddCallback' from
    incompatible pointer type
    /tmp/ccqpdNZ7.o(.text+0x29): In function `main':
    : undefined reference to `XtVaAppInitialize'
    /tmp/ccqpdNZ7.o(.text+0x40): In function `main':
    : undefined reference to `XmCreatePushButton'
    /tmp/ccqpdNZ7.o(.text+0x51): In function `main':
    : undefined reference to `XtManageChild'
    /tmp/ccqpdNZ7.o(.text+0x60): In function `main':
    : undefined reference to `_XmStrings'
    /tmp/ccqpdNZ7.o(.text+0x68): In function `main':
    : undefined reference to `XtAddCallback'
    /tmp/ccqpdNZ7.o(.text+0x76): In function `main':
    : undefined reference to `XtRealizeWidget'
    /tmp/ccqpdNZ7.o(.text+0x84): In function `main':
    : undefined reference to `XtAppMainLoop'
    collect2: ld returned 1 exit status

    [root@localhost temp]#

    Please help me with this.

    Thanks

    Rana Knight

  2. Re: NEWBIE - How to compile program using Motif libraries ?

    x-no-archive: yes

    You have to compile in the Intrinsics ("Xt") libs, they are usually called libXt.so.something. In most systems it suffices with adding "-lXt" to the command line.

    --
    Please keep the 'x-no-archive: yes' header.

    To reach me by email: transform my account name like IBM -> HAL.


  3. Re: NEWBIE - How to compile program using Motif libraries ?

    Rana Knight wrote:

    > I am using RedHat Linux 9 with OpenMotif.
    >
    > I tried to compile a program with the following command line -
    >
    > gcc -I /usr/X11R6/LessTif/Motif1.2/include -L
    > /usr/X11R6/LessTif/Motif1.2/lib push2.c -o push -lX11


    LessTif != OpenMotif. The OpenMotif includes, if installed, are in
    /usr/X11R6/include, the libs in /usr/X11R6/lib. Ideally, you would want to
    install OpenMotif 2.1.30 instead of the seriously buggy OM 2.2 which comes
    with RH 9.

    You also need to link to Xm and Xt. Something like:

    gcc -Wall -I/usr/X11R6/include -L/usr/X11R6/lib push2.c -o
    push -lXm -lXt -lX11

    ("-Wall" is optional of course, but I would suggest it's a good idea.)

    > /* Prototype Callback function */
    >
    > void pushed_fn(Widget , XtPointer ,
    > XmPushButtonCallbackStruct *);


    This will give you warnings like the first one below. The third argument is
    type XtPointer, you have to cast it to XmPushButtonCallbackStruct * in the
    function code (if you need it).

    > push2.c: In function `main':
    > push2.c:25: warning: passing arg 3 of `XtAddCallback' from
    > incompatible pointer type


    > /tmp/ccqpdNZ7.o(.text+0x29): In function `main':
    >> undefined reference to `XtVaAppInitialize'

    > /tmp/ccqpdNZ7.o(.text+0x40): In function `main':
    >> undefined reference to `XmCreatePushButton'

    [...]

    All these are caused by the missing -lXm -lXt.

    > [root@localhost temp]#


    Please don't say that you're developing and compiling as root. That's a
    recipe for disaster.

    --
    Per Espen Hagen



+ Reply to Thread