LD_LIBRARY_PATH doesn't seem to work

不羁的心 提交于 2019-12-03 17:17:39

问题


I'm 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 fine.

So I added the path like so:

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

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

gcc -o test  test.c -lg2c

still doesn't work, it gives the same error, I can't figure out why.

I'm 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: I tried using LIBRARY_PATH instead, now I get a different error:

gcc: spec failure: unrecognized spec option 'M'

I have no idea what it means.


回答1:


Try setting LIBRARY_PATH, instead of LD_LIBRARY_PATH.

From the gcc man page:

LIBRARY_PATH

The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH. When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using GCC_EXEC_PREFIX. Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).




回答2:


Make sure that you export LD_LIBRARY_PATH after modifying it. Otherwise GCC won't 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


来源:https://stackoverflow.com/questions/13292261/ld-library-path-doesnt-seem-to-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!