我正在尝试编译测试文件:
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).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。