LD_LIBRARY_PATH doesn't seem to work

I am trying to compile a test file:

gcc -o test test.c -lg2c 

but I get the error:

 /usr/bin/ld: cannot find -lg2c 

If I use:

 gcc -o test test.c -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -lg2c 

then it works great.

So, I added the path as follows:

 LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/3.4.6:$LD_LIBRARY_PATH 

and when I use $LD_LIBRARY_PATH , it is listed there, but:

 gcc -o test test.c -lg2c 

still does not work, it gives the same error, I can’t understand why.

I am using CentOS (2.6.32-279.9.1.el6.x86_64), any help would be greatly appreciated.


EDIT : compiler version:

 rpm -qa | grep gcc gcc-4.4.6-4.el6.x86_64 compat-gcc-34-g77-3.4.6-19.el6.x86_64 libgcc-4.4.6-4.el6.x86_64 compat-gcc-34-3.4.6-19.el6.x86_64 gcc-gfortran-4.4.6-4.el6.x86_64 libgcc-4.4.6-4.el6.i686 gcc-c++-4.4.6-4.el6.x86_64 

EDIT : instead, I tried using LIBRARY_PATH , now I get another error:

 gcc: spec failure: unrecognized spec option 'M' 

I have no idea what that means.

+7
source share
2 answers

Try setting LIBRARY_PATH instead of LD_LIBRARY_PATH .

On the gcc man page:

library_path

The value LIBRARY_PATH is a colon-separated list of directories, like PATH. When it is configured as its own compiler, GCC tries in this way the specified directories when searching for special linker files if it cannot find them using GCC_EXEC_PREFIX. GCC binding also uses these directories when searching for regular libraries for -l (but directories specified with -L first).

+8
source

Make sure you export LD_LIBRARY_PATH after changing it. Otherwise, GCC will not be able to see the modified version.

 LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/3.4.6:$LD_LIBRARY_PATH export LD_LIBRARY_PATH gcc -o test test.c -lg2c 
+3
source

All Articles