I have a build where I wish to link against and load a specific version of a library and a different version of the same library is installed on the system. I'm using a -L option to point to the version that I wish to link against but gcc still seems to choose the installed version. Is there a way to force gcc to search the directory specified with the -L option before it searches the standard locations?
I'm running Centos 6.5 with gcc 4.4.7. Here are the relevant libs and directories, zlib-devel is not installed
/lib64/libz.so.1.2.3
/lib64/libz.so.1 -> libz.so.1.2.3
/home/richj/product/zlib/lib/libz.so.1.2.8
/home/richj/product/zlib/lib/libz.so -> libz.so.1.2.8
/home/richj/product/zlib/lib/libz.so.1 -> libz.so.1.2.8
/home/richj/product/zlib/include/zlib.h
/home/richj/product/foo/libfoo.so
/home/richj/product/foo/foo.h
/home/richj/product/bar/bar.c
Main in bar.c calls foo in libfoo.so and foo calls inflateInit in libz Here are the compile commands for libfoo.so and bar. Both the library and the program compile and run without error.
/usr/bin/gcc -c -fPIC -Wall -g -I../zlib/include foo.c
/usr/bin/gcc -shared -o libfoo.so foo.o
/usr/bin/gcc -Wall -g -I../foo -L../foo -lfoo -L../zlib/lib -lz bar.c -o bar
$ldd bar
linux-vdso.so.1 => (0x00007fffd67ff000)
libfoo.so => ../foo/libfoo.so
libz.so.1 => /lib64/libz.so.1
libc.so.6 => /lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
So the question is why is it not linking against and loading the version of zlib that I point to in the compile command?