Ste*_*hen 8 c path shared-libraries ld
我正在为一个类评分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
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
/usr/bin/ld: cannot find -lgsl
collect2: ld returned 1 exit status
make: *** [all] Error 1
Run Code Online (Sandbox Code Playgroud)
我正在使用gcc v 4.1.2.如果我使用gcc v 4.4,我实际上没有得到错误,但我不知道为什么.我的链接器是:
ld -V
GNU ld version 2.17.50.0.6-12.el5 20061020.
Run Code Online (Sandbox Code Playgroud)
Kje*_*sen 12
您可以尝试使用环境变量LIBRARY_PATH
来自man 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,让运行时链接程序找到库.