我正在对课程的 C 和 C++ 文件进行评分,并且此作业使用 GSL 库。由于我的计算机没有 root 权限,因此我的 GSL 库安装在我的主目录中,因此我需要告诉编译器和链接器在哪里可以找到它。
当我自己编写程序时,这不是问题,因为我只需向 gcc 添加适当的 -L 和 -I 标志即可。
但是当我编译学生的文件时,我不想编辑他们的每一个 makefile。相反,我想将适当的目录放入环境变量中,以便它无缝地发生。
为此,我使用库导出了以下变量或包含位置:
C_INCLUDE_PATH、CPLUS_INCLUDE_PATH、LIBRARY_PATH 和 LD_LIBRARY_PATH
但是当我编译学生的项目时,
gcc -Wall -o MC_thread MC_thread.c -lgsl -lgslcblas -lpthread -lm
我收到以下错误:
/usr/bin/ld: cannot find -lgsl
collect2: ld returned 1 exit status
make: *** [all] Error 1
我正在使用 gcc v 4.1.2。如果我使用 gcc v 4.4,我实际上不会收到错误,但我不知道为什么。我的链接器是:
ld -V
GNU ld version 2.17.50.0.6-12.el5 20061020.
您可以尝试使用环境变量 LIBRARY_PATH
From man gcc http://linux.die.net/man/1/gcc(至少4.4版本)
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 让运行时链接器找到库。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)