simple X window program not compile, plz help

Alan Coopersmith alan.coopersmith at oracle.com
Sun Oct 31 20:24:36 PDT 2010


eric lin wrote:
> Dear X window advanced programers:
> 
>   on my ubuntu/linux, I tried a simple x window program by c
> as following:
> 
> ---------------------------------------
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include <X11/Intrinsic.h> /* for creation routines */
> #include <X11/StringDefs.h>    /* for resource names */
> #include <X11/Xaw/Form.h>      /* to define the formWidgetClass  */
> 
> int main()
> {
>    XtAppContext appContext;
>    Widget toplevel, form;
> 
>    toplevel = XtVaAppInitialize( &appContext, 
>                                  "2D-Editor", /* Application class name   */
>                                  NULL, 0, /* option list (not used)
>                                  &argc, argv, /* command line parameters */
>                                  NULL,     /* fallback resources (not
>                                               used)                      */
>                                  NULL      /* end of the variable
>                                               argument list              */
>                                 , 0);
> 
>     if (toplevel == NULL) {
>        fprintf(stderr, "Failed to connect to X server!" );
>        exit(1);
>     }
>    return (0);
> }
> 
> ---------------------------------------------------------------
> this is I copy from page 146 and page 150 of book "X Window Programming from SCRATCH"
> 
> ----------------
> eric at eric-laptop:~$ gcc try2.c
> try2.c: In function ‘main’:
> try2.c:20: warning: not enough variable arguments to fit a sentinel
> /tmp/cc06w66r.o: In function `main':
> try2.c:(.text+0x41): undefined reference to `XtVaAppInitialize'
> collect2: ld returned 1 exit status

You need to tell it what libraries to link with - the automated way would be
	gcc try2.c `pkg-config --libs xt`

The manual way would be
	gcc try2.c -lXt -lX11

When you start calling Xaw functions, you'd add it:
	gcc try2.c `pkg-config --libs xt xaw7`
or
	gcc try2.c -lXaw -lXt -lX11

But really, if you want to learn to write apps that people will use, you should
be learning GTK or Qt, not the ancient and mostly unmaintained Xaw.

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System




More information about the xorg mailing list