Syslab Sales and Services Pvt Ltd. wrote:

> > Static libraries have to be specified *after* the file which uses
> > them. When a static library is linked, only those functions which are
> > known to be required are linked in.
> > 
> > Try putting the -lgtk last.
> 
>       When I try putting it last, again I get tons of error messages
> like (hundreds of such messages:
> 
> /usr/src/bs/BUILD/gtk+970925/gdk/gdkwindow.c:1186: undefined reference to
> `g_free'
> /usr/src/bs/BUILD/gtk+970925/gdk/gdkwindow.c:1188: undefined reference to
> `XFree'
> /usr/lib/libgdk.a(gdkxid.o): In function `gdk_xid_table_insert':
> /usr/src/bs/BUILD/gtk+970925/gdk/gdkxid.c:33: undefined reference to
> `g_warning'

By `last', I meant after sample.c (which should be first).

libgtk appears to depend upon libgdk, so you need to list -lgdk after
-lgtk. libgdk itself presumably requires libX11, so you would need to
use e.g.

        -lgtk -lgdk -L/usr/X11/lib -lX11

There may also be other dependencies. In general, any library upon
which an object or library depends must be listed *after* that file in
the link command when performing static linking. `ldd' should display
the dependencies.

However, this is irrelevant. You shouldn't be trying to link
statically unless you have a specific reason to do so.

> > > And when I use
> > >         gcc -o samp -lgtk sample.c
> > > 
> > > I get a whole lot of error messages some of which are as follows...
> > 
> > [undefined gdk_* references snipped]
> > 
> > You also need need libgdk, e.g.
> > 
> >     gcc -o samp -lgtk -lgdk sample.c
> > 
> 
> this is what is happening
> 
> [root@localhost /root]# gcc -o samp -lgtk -lgdk sample.c
> ld: warning: libc.so.5, needed by /usr/i486-linux-libc5/lib/libX11.so.6,
> may conflict with libc.so.6

You're linking against the wrong X libraries (i.e. the libc-5
versions).

You need to add `-L/usr/X11/lib', e.g.

        gcc -o samp sample.c -lgtk -lgdk -L/usr/X11/lib -lX11

You may need other libraries; I don't have GTK installed, so I can't
tell.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to