LD_LIBRARY_PATH似乎不工作 [英] LD_LIBRARY_PATH doesn't seem to work
问题描述
我正在尝试编译测试文件:
gcc -o test test.c -lg2c
但我得到错误:
code> / usr / bin / ld:找不到-lg2c
/ p>
gcc -o test test.c -L / usr / lib / gcc / x86_64-redhat-linux / 3.4.6 -lg2c
那么它可以正常工作。
我添加了这样的路径:
LD_LIBRARY_PATH = / usr / lib / gcc / x86_64-redhat-linux / 3.4.6:当我使用 $ LD_LIBRARY_PATH
时,$ LD_LIBRARY_PATH
<但是:
gcc -o test test.c -lg2c
仍然无法正常工作,它也会出现同样的错误,我无法找出原因。
我使用的是CentOS(2.6.32-279.9.1.el6.x86_64),任何帮助将非常感激。
EDIT :编译器版本:
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 :我尝试使用
LIBRARY_PATH
,现在我得到一个不同的错误:gcc:spec failed:unrecognized spec option'M'
我不知道这是什么意思。
解决方案code> LIBRARY_PATH ,而不是
LD_LIBRARY_PATH
。
c $ c> gcc 手册页:
LIBRARY_PATH
LIBRARY_PATH的值是以冒号分隔的目录列表,
非常类似于PATH。当配置为本机编译器时,GCC会在搜索特殊链接器文件时尝试这样指定的
目录,如果
它不能使用GCC_EXEC_PREFIX找到它们。链接使用GCC也使用
这些目录,当搜索-l
选项的普通库时(但是使用-L指定的目录首先)。
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.
解决方案Try setting
LIBRARY_PATH
, instead ofLD_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).
这篇关于LD_LIBRARY_PATH似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!