Reputation: 324
I have a Hello, World C program for X11 downloaded from somewhere. It compiles, but doesn't link properly.
The 32-bit Ubuntu version runs in VM VirtualBox under Windows 7. The compile and link command I use (one of many variations I tried) is:
gcc -L/usr/lib/i386-linux-gnu -lX11 hellowin.c
Apparently, that is the correct location, as 'locate libX11' gives me:
/usr/lib/i386-linux-gnu/libX11.a
amongst other such files (mostly .so ones). The errors I get are like this:
....undefined reference to 'XOpenDisplay'
What am I doing wrong?
Edit: It now works if I leave out -L and move the -l to after the file as suggested. Eg:
gcc hellowin.o -lX11
or specifying the library directly, but this only works with .so, not .a:
gcc hellowin.o /usr/lib/i386-linux-gnu/libX11.so
(The build instructions with the Hello, World source used -L and -l, and they were both placed before the object file name.)
Upvotes: 1
Views: 5392
Reputation: 1
Order of arguments to gcc
and linking matters a big lot (compiler options, sources files, object files, libraries from high-level to low-level ones):
gcc -Wall -g hellowin.c -L/usr/lib/i386-linux-gnu -lX11 -o hellowin
then try
./hellowin
you might need to use the debugger with
gdb ./hellowin
Upvotes: 1
Reputation: 26
I compiled a version of "Hello world" from rosettacode and I have not recieved any errors. Try using another version of Ubuntu (mine was an old version from VritualBox: Ubuntu 12). I was using Windows 10. (Although I think this should not matter).
Maybe you forgot to include one of the libraries.
If anything does not work, please give us some of the code that is not running.
http://rosettacode.org/wiki/Window_creation/X11#Xlib
Upvotes: 0