How to CORRECTly install the gsl library on Linux?

I had a problem installing GNU Scientific Library (gsl). I put the package on my desktop and did "./configure", "make" and "sudo make install" according to the document. I checked the directory / usr / local / include, there is a newly created folder "gsl". But when I tried to use the functions provided by the library, the error "undefined to the error" gsl_sf_beta_inc "" 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; } 

I realized that the problem could be caused by the fact that I put the package on the desktop so that the binary code generated by the "make" command goes there, which is wrong. So is my guess correct? If so, where should I put them? If this is not so, what should I do? Thanks.

+4
source share
2 answers

You need to link the library if make install was successful.

Gsl documentation says this should work
(note the two necessary bind options for gsl to work: "-lgsl -lgslcblas"):

 gcc -I/usr/local/include -L/usr/local/lib main.c -o main -lgsl -lgslcblas -lm 

Alternative "cblas" instead of gsl cblas are also possible: alternative cblas for gsl

+10
source

Use pkg-config --libs gsl to find out what the necessary linkers should be and then just connect them. An optional thing is to check pkg-config --cflags gsl . The second gives you a directory of included files if they are not installed in the default /usr/include/ directory. If you installed it, you can simply ignore it.
The output of pkg-config --libs gsl will look like this: -lgsl -lgslcblas -lm
This means that these three must be connected. Therefore, compiling your program, you do this using gcc name.c -lgsl -lgslcblas -lm

+2
source

All Articles