如何在Linux中正确安装gsl库? [英] How to CORRECTLY install gsl library in Linux?
问题描述
在安装GNU科学库(gsl)时遇到问题. 根据随附的文档,我将程序包放在桌面上,并执行了"./configure"、make"和"sudo make install".我检查了/usr/local/include目录,其中有一个新创建的"gsl"文件夹.但是,当我尝试使用该库提供的功能时,发生了未定义对'gsl_sf_beta_inc'的引用"错误.这是我的代码.
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.
#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;
}
我感觉到问题可能是由于我将软件包放在桌面上而导致的,所以"make"命令生成的二进制代码就在那儿,这是错误的. 所以,我的猜测正确吗?如果是的话,我应该放在哪里?如果不是,我该怎么办? 谢谢.
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 install
成功.
You need to link the library, assuming the make install
was successful.
gsl的文档说,这应该有效
(请注意,要使gsl正常工作,必须使用两个必要的链接选项:"-lgsl -lgslcblas"):
The gsl's documentation says this should work
(note the two necessary linking options for gsl to work: "-lgsl -lgslcblas"):
gcc -I/usr/local/include -L/usr/local/lib main.c -o main -lgsl -lgslcblas -lm
也可以按照以下方式用替代的"cblas"代替gsl的cblas:
Alternative "cblas" instead of gsl's cblas is also possible as per: alternate cblas for gsl
这篇关于如何在Linux中正确安装gsl库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!