gcc can't find -lX11

979 Views Asked by At

I've used linuxbrew to install gcc 5.3 on a machine on which I don't have sudo access. I now want to link with X11:

> gcc test.c -lX11
ld: cannot find -lX11

I've checked that libX11.so exists in /usr/lib64/ which is on the compiler's LIBRARY_PATH. If I use the system's gcc it works fine, but I need a newer version to compile my actual program.

2

There are 2 best solutions below

0
On BEST ANSWER

According to this comment by a linuxbrew developer,

linuxbrewed gcc removes /usr/lib64 from the library path because mixing system libraries with brewed libraries creates havoc.

The solution is to brew install linuxbrew/xorg/xorg.

1
On

use -L flag, like this -L/usr/lib64, or you can specify full path to library like this gcc test.c /usr/lib64/libX11.so