linux – LD_LIBRARY_PATH似乎不起作用

我正在尝试编译测试文件
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

然后它工作正常.

所以我添加了这样的路径:

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),任何帮助将不胜感激.

编辑:编译器版本:

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

编辑:我尝试使用LIBRARY_PATH,现在我得到一个不同的错误

gcc: spec failure: unrecognized spec option 'M'

我不知道这意味着什么.

解决方法

尝试设置LIBRARY_PATH,而不是LD_LIBRARY_PATH.

从gcc手册页:

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).

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...