simple X window program not compile, plz help
eric lin
fsshl at luxmail.com
Sun Oct 31 20:57:22 PDT 2010
dear Alan or any x window user/programers:
it compile success by your last suggestion
but when I run it,
Segmentation fault (anyone can tell me why?)(that book's code actually is already illegal on my system's x window grammer, plus
I have hard time to figure it out what that book's authors's explanation. But I won't abondon it in short time.)
that book is really pretty unorganized, especially code in ununiform. But that is so far I can get most approach to X on linux, which is I borrow from Los Angeles's central city library at downtown. I also see another book, "Motif", in that library also doing graphic on Unix, written by c++. I search a little bit on google's motif part, i find a simple c code and I copy it and try to compile it on my system, but it not work
-------------------------------
root at eric-laptop:/home/eric# gcc try3.c -lXaw -lXt -lX11 -lXm
try3.c:2:20: error: Xm/Xm.h: No such file or directory
try3.c:3:22: error: Xm/PushB.h: No such file or directory
try3.c:8: error: expected ‘)’ before ‘*’ token
try3.c: In function ‘main’:
try3.c:13: error: ‘Widget’ undeclared (first use in this function)
try3.c:13: error: (Each undeclared identifier is reported only once
try3.c:13: error: for each function it appears in.)
try3.c:13: error: expected ‘;’ before ‘top_wid’
try3.c:14: error: ‘XtAppContext’ undeclared (first use in this function)
try3.c:14: error: expected ‘;’ before ‘app’
try3.c:16: error: ‘top_wid’ undeclared (first use in this function)
try3.c:16: error: ‘app’ undeclared (first use in this function)
try3.c:16: error: ‘NULL’ undeclared (first use in this function)
try3.c:19: error: ‘button’ undeclared (first use in this function)
try3.c:25: error: ‘XmNactivateCallback’ undeclared (first use in this function)
try3.c:25: error: ‘pushed_fn’ undeclared (first use in this function)
try3.c: At top level:
try3.c:32: error: expected ‘)’ before ‘w’
root at eric-laptop:/home/eric# cat try3.c
#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");
}
---------------------------------------------
so if anyone know how to make it compile, I will be highly appreciate and I am glad to borrow that Motif book from my citi library again.
plz help
and
thx your time and effort and patience, Eric, fsshl at luxmail.com
----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
-----------------
--- alan.coopersmith at oracle.com wrote:
From: Alan Coopersmith <alan.coopersmith at oracle.com>
To: fsshl at luxmail.com
CC: xorg at lists.freedesktop.org
Subject: Re: simple X window program not compile, plz help
Date: Sun, 31 Oct 2010 20:24:36 -0700
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
_____________________________________________________________
Luxmail.com is spam free. However, we do not throw your important emails into spam box like other defective email systems.
More information about the xorg
mailing list