Help linking my little Xwindow test program

Help linking my little Xwindow test program

Post by Michael B. Willia » Wed, 25 Jun 2003 23:31:18



all,

 I running Slakware 9.0 / KDE 3.1. I don't understand what I'm doing wrong here

gcc -Wall -c -o xTest.o xTest.c
gcc xTest.o -o xTest -lX11

ld cannot find -lX11

Thanks in advance

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>

main ()
{
        Display *display;
        Window window;
        int screen;
        unsigned long foreground, background;

        /* connect to the X server */
        display = XOpenDisplay ("");

        if (display == NULL)
        {
                fprintf (stderr, "cannot connect to server\n");
                exit (EXIT_FAILURE);
        }

        /* get default screen */
        screen = DefaultScreen (display);

        /* get black and white representation on current screen */
        background = WhitePixel (display, screen);
        foreground = BlackPixel (display, screen);

        /* Create window at (100,50), width 350, height 250, border width
           2, in default root  */
        window = XCreateSimpleWindow (display,
                DefaultRootWindow(display), 100, 50, 350, 250, 2,
                foreground, background);

        if (window == NULL)
        {
                fprintf (stderr, "cannot open window\n");
                exit (EXIT_FAILURE);
        }

        /* pop this window up on the screen */
        XMapRaised (display, window);

        /* flush X request queue to server */
        XFlush (display);
        sleep (5);

        XDestroyWindow(display, window);
        XCloseDisplay (display);

        exit (EXIT_SUCCESS);

 
 
 

Help linking my little Xwindow test program

Post by Jens.Toerr.. » Wed, 25 Jun 2003 23:53:13



Quote:>  I running Slakware 9.0 / KDE 3.1. I don't understand what I'm doing wrong here
> gcc -Wall -c -o xTest.o xTest.c
> gcc xTest.o -o xTest -lX11
> ld cannot find -lX11

Try to insert -L/usr/X11R6/lib before the -lX11 bit, this should tell
the linker where to find the library.
                                         Regards, Jens
--
      _  _____  _____

  _  | |  | |    | |
 | |_| |  | |    | |          http://www.physik.fu-berlin.de/~toerring
  \___/ens|_|homs|_|oerring

 
 
 

Help linking my little Xwindow test program

Post by Michael B. Willia » Thu, 26 Jun 2003 04:24:06


Quote:

> Try to insert -L/usr/X11R6/lib before the -lX11 bit, this should tell
> the linker where to find the library.
>                                          Regards, Jens

Thanks Jens - that's what I needed