LD_LIBRARY_PATH 似乎不起作用 [英] LD_LIBRARY_PATH doesn't seem to work

查看:41
本文介绍了LD_LIBRARY_PATH 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个测试文件:

I'm trying to compile a test file:

gcc -o test  test.c -lg2c

但我得到了错误:

/usr/bin/ld: cannot find -lg2c

如果我使用:

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

当我使用 $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.

我正在使用 CentOS (2.6.32-279.9.1.el6.x86_64),任何帮助将不胜感激.

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

编辑:编译器版本:

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,但现在我得到一个不同的错误:


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.

推荐答案

尝试设置 LIBRARY_PATH,而不是 LD_LIBRARY_PATH.

Try setting LIBRARY_PATH, instead of LD_LIBRARY_PATH.

来自 gcc 手册页:

LIBRARY_PATH

LIBRARY_PATH

LIBRARY_PATH 的值是以冒号分隔的目录列表,很像PATH.当配置为本机编译器时,GCC 会尝试搜索特殊链接器文件时指定的目录,如果它无法使用 GCC_EXEC_PREFIX 找到它们.使用 GCC 链接也使用为 -l 搜索普通库时的这些目录选项(但使用 -L 指定的目录在前).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆