[英]LD_LIBRARY_PATH doesn't seem to work
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:当我使用
$LD_LIBRARY_PATH
它列在那里,但是:
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.我正在使用 CentOS (2.6.32-279.9.1.el6.x86_64),任何帮助将不胜感激。
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:编辑:我尝试改用
LIBRARY_PATH
,现在出现不同的错误:
gcc: spec failure: unrecognized spec option 'M'
I have no idea what it means.我不知道这意味着什么。
Try setting LIBRARY_PATH
, instead of LD_LIBRARY_PATH
.尝试设置
LIBRARY_PATH
,而不是LD_LIBRARY_PATH
。
From the gcc
man page:从
gcc
手册页:
LIBRARY_PATH
LIBRARY_PATH
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH.
LIBRARY_PATH 的值是以冒号分隔的目录列表,很像 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.
当配置为本地编译器时,GCC 在搜索特殊链接器文件时会尝试这样指定的目录,如果它无法使用 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).
在为 -l 选项搜索普通库时,使用 GCC 进行链接也会使用这些目录(但首先使用 -L 指定的目录)。
Make sure that you export LD_LIBRARY_PATH
after modifying it.确保在修改后导出
LD_LIBRARY_PATH
。 Otherwise GCC won't be able to see the modified version.否则 GCC 将无法看到修改后的版本。
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
Create a new folder inside your home directory (not root directory!).在您的主目录(不是根目录!)中创建一个新文件夹。 Copy all the required library associated with
-lg2c
from /usr/lib/gcc/x86_64-redhat-linux/3.4.6
to this folder.将与
-lg2c
关联的所有必需库从/usr/lib/gcc/x86_64-redhat-linux/3.4.6
复制到此文件夹。
Set the path in your bash profile to this new folder.将 bash 配置文件中的路径设置为这个新文件夹。
I also got this issue, and solve it with this workaround.我也遇到了这个问题,并通过此解决方法解决了它。 Perhaps we (as non-root users) don't have the necessary access/right to
/usr/lib/gcc/x86_64-redhat-linux/3.4.6
也许我们(作为非 root 用户)没有必要的访问权限/权限
/usr/lib/gcc/x86_64-redhat-linux/3.4.6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.