/usr/bin/ld Cannot Find Library Path Linkage Problem

STUDY : Open Source Application MakeFile Important Environment Variable.
CFLAGS     - C Compiler Flags.
LDFLAGS  - Library Path
CC C          - Compiler Command.
-L - User Define Library path Example -L /usr/X11R6/lib/.
-l  - Search from Common Library Path(/lib) -lX11.
#gcc -L /folder/contain/library/path/event/ -levent.

When I try to install Open Source Application I got the Following ERROR MESSAGE:
/usr/bin/ld: cannot find -lX11
collect2: ld returned 1 exit status
make: *** [eterm] Error 1

REASON : This type of issue Happened when it does not find the Proper Libraries in the Default Path(lib)  or (-L) Specified Location.


FULL ERROR MESSAGE : cc -o eterm main.o init.o close.o font.o gc.o api.o sink.o select.o serial.o print.o tot_compose.o -O2 -Wall -fomit-frame-pointer -march=i386 -s -L /usr/X11/lib libansi.a libvt.a libsie.a libtel.a libwy.a -lX11 -L ../../OPT/MLT-Display-Lib/ -liscdisp -lstdc++ -L ../../opt/getval -lgetval
/usr/bin/ld: cannot find -lX11
collect2: ld returned 1 exit status
make: *** [eterm] Error 1

SOLUTION:
1) We have to install the Proper Library Package.
2) Or if it is already installed, we need to Link the Correct Library Path with -L and -l Option.
....-march=i386 -s -L /usr/X11/lib .... libtel.a libwy.a -lX11
From the Above Statement it tries to find the Library X11 from /usr/X11/lib.
 But it can't find, Because  X11 Located in /usr/X11R6/lib/.
So we have to replace from /usr/X11/lib to /usr/X11R6/lib. Change this Variable (LDFLAGS) in Makefile.

How To Find Out,Whether Library Package Is Already Install Or Not.
METHOD 1
#gcc program.c -lgetval
1)-lgetval is Library.
2) It is located under Default Library Path /lib
3) To find #locate getval | grep lib
File is located under /lib/libgetval.so
METHOD 2
#gcc graphics.h -L /usr/X11/lib –lX11
1) We have to Search Xll library path under /usr/X11/lib
2) #find /usr/X11/lib –name X11*
3) If it is not located, we have to search whether is it located in any another Path. Like
4)#find / -name X11*
5)if it is locate then change –L Correct Directory Path or
 6)if it can't find anywhere else, Then we have to install particular library.

Similar Error Message:
/usr/bin/ld: cannot find -lz
 
/usr/bin/ld: cannot find -lc
 
/usr/bin/ld: cannot find -lgcc_s_32

/usr/bin/ld: cannot find -lXaw
 
/usr/bin/ld: cannot find -lImlib2
 
/usr/bin/ld: cannot find -lperl


Problem And Solution
$mpic++ -o abc b.o m.o -lg2c
ld: cannot find -lg2c
#find / -name g2c
Actual library file locatede under.
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/libg2c.a
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/libg2c.so
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/32/libg2c.a
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/32/libg2c.so

g2c library located under /usr/lib/gcc/x86_64-redhat-linux/3.4.6/.
$mpic++ -o abc b.o m.o -L /usr/lib/gcc/x86_64-redhat-linux/3.4 -lg2c

Related post