Click to See Complete Forum and Search --> : Simple X11 App. compilation problem!


q6z4k
07-01-2005, 05:43 PM
Hi!
Can anyone please tell me why, when I compile this source-code, I get these errors:
user@host:~$ gcc simple-window.c -lx11
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld: cannot find -lx11 collect2: ld returned 1 exit status


Here is the source code: http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/simple-window.c

Thank you!

bwkaz
07-01-2005, 06:26 PM
Because of two large problems and two much more minor problems: :)

First, Linux is case sensitive, so you need to use -lX11 (capital X).

Second, the compiler (actually the linker, but yeah) needs to know where to find the libX11 library file, because it's not in the standard search path. The standard search path is /lib and /usr/lib, but libX11 is usually in /usr/X11R6/lib. So you need to tell it to look there, using the -L switch:

gcc simple-window.c -lX11 -L/usr/X11R6/lib

Third, not everyone has a /usr/include/X11 directory (or symlink), so it's generally a good idea to provide an extra include path (to /usr/X11R6/include) to find the X include files on those machines:

gcc simple-window.c -lX11 -L/usr/X11R6/lib -I/usr/X11R6/include

(That's a capital i, not a lowercase L. Lowercase L is "link this library in", while capital i is "add this directory to the include search path.)

Finally, I get a warning when I compile your code about "return type of main is not int". Your main function MUST be defined as returning an int according to the C standard, although some compilers (e.g. ones for DOS) do not actually require it. If you compile and run your code on a system that does require it but does not error, though, you can break the C runtime when your main function returns.