tags:

views:

311

answers:

4

I am using GCC, what switches do I need to add to link with Xlib? After searching, all I could find was -lX11, but that gave me ld: library not found for -lX11

I am using a mac (10.6), but I would not like anything that is Mac specific.

+1  A: 

You also need -L/usr/X11/lib. It's not exactly Mac-specific, but you will find that the location of these libs will vary a bit from system to system.

bmargulies
+3  A: 
$ locate libX11
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.2.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.a
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.2.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.dylib
/usr/X11/lib/libX11.6.2.0.dylib
/usr/X11/lib/libX11.6.dylib
/usr/X11/lib/libX11.dylib
/usr/X11/lib/libX11.la

I'd try

gcc [...] -L/usr/X11/lib -lX11 [...]

to set the search path for libraries.

dmckee
+1  A: 

You'd be surprised, but sometimes -L/usr/X11R6/lib -lX11 is the answer -_-.

Kornel Kisielewicz
+9  A: 

You can usually use pkg-config to determine the flags you need to pass:

gcc `pkg-config --cflags --libs x11` -o my-program my-program.c
Brian Campbell
Hey! I didn't know that was there. And I've always liked that kind of facility when individual programs supply it (e.g. `root-config` with http://root.cern.ch/).
dmckee
Hmmm...mine seems to be supplied by fink (on Mac OS 10.5).
dmckee
+1 : I love the answers when someone asks for a fish and gets a fishing rod in return :)
Kornel Kisielewicz