如何在 Linux 中正确安装 gsl 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7033927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to CORRECTLY install gsl library in Linux?
提问by seemuch
I got a problem while installing the GNU Scientific Library (gsl). I put the package on my desktop, and did "./configure", "make", and "sudo make install", according to the document included. I checked the /usr/local/include directory, there is a newly created "gsl" folder in there. But When I tried to use the functions provided by the library, the "undefined reference to 'gsl_sf_beta_inc'" error occurred. Here is my code.
我在安装 GNU 科学库 (gsl) 时遇到问题。根据包含的文档,我将软件包放在桌面上,并执行了“./configure”、“make”和“sudo make install”。我检查了 /usr/local/include 目录,那里有一个新创建的“gsl”文件夹。但是当我尝试使用库提供的函数时,出现了“对'gsl_sf_beta_inc'的未定义引用”错误。这是我的代码。
#include <stdio.h>
#include <gsl/gsl_sf_gamma.h>
int main (void)
{
double a = 20;
double b = 1000;
double x = 0.5;
double result = gsl_sf_beta_inc(a, b, x);
printf("%f/d", result);
return 0;
}
I sensed that the problem might be caused by the fact I put the package on the desktop, so the binary code generated by the "make" command goes there, which is wrong. So, is my guess correct? If it is, where should I put them? If it is not, what should I do? Thanks.
我感觉问题可能是我把包放在桌面上造成的,所以“make”命令生成的二进制代码放在那里,这是错误的。那么,我的猜测正确吗?如果是,我应该把它们放在哪里?如果不是,我该怎么办?谢谢。
采纳答案by Vinicius Kamakura
You need to link the library, assuming the make install
was successful.
假设make install
成功,您需要链接库。
The gsl's documentationsays this should work
(note the two necessary linking options for gsl to work: "-lgsl -lgslcblas"):
在GSL的文档说,这应该工作
(注意,GSL工作的两个必要连接选项:“-lgsl -lgslcblas”):
gcc -I/usr/local/include -L/usr/local/lib main.c -o main -lgsl -lgslcblas -lm
Alternative "cblas" instead of gsl's cblas is also possible as per: alternate cblas for gsl
也可以使用替代“cblas”代替 gsl 的 cblas:alternative cblas for gsl
回答by Nidish Narayanaa
Use pkg-config --libs gsl
to find out what the necessary linkers are to be and then just link them. An optional thing would be to check pkg-config --cflags gsl
. The second gives you the directory of the include files if they are not installed in the default /usr/include/
directory. If you've installed it there you can just ignore that.
The output of pkg-config --libs gsl
would be-lgsl -lgslcblas -lm
That means that those three have to be linked. So while compiling your program you do that by,gcc name.c -lgsl -lgslcblas -lm
使用pkg-config --libs gsl
找出所需的接头是是,然后只需将它们链接。一个可选的事情是检查pkg-config --cflags gsl
. 如果它们未安装在默认/usr/include/
目录中,则第二个为您提供包含文件的目录。如果你已经在那里安装了它,你可以忽略它。
的输出pkg-config --libs gsl
将是-lgsl -lgslcblas -lm
这意味着这三个必须链接。所以在编译你的程序时,你这样做,gcc name.c -lgsl -lgslcblas -lm