1. Download GSL:
https://www.gnu.org/software/gsl/
2. It will be a compressed tar file, like gsl-x.x.tar.gz
3. Place this file in the home
4. Open the terminal and unpack this downloaded file:
$ tar -zxvf gsl-x.x.tar.gz
5. A new folder will be created. cd to that folder.
6. Now we will configure, make and install GSL:
$ ./configure
$ make
$ sudo make install
Each of these steps may take some time. Wait patiently.
7. Close the terminal and open .bashrc file in the home. It is a hidden file. If required use Ctrl+H to access it.
Edit this file to add:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
8. Save the edited file and close it.
9. Now get back to the terminal and compile a C code that uses GSL. For example, use the test code testgsl.c:
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
To compile:
$ gcc -Wall testgsl.c -o run -lgsl -lgslcblas -lm
10. Now run the compiled code:
$ ./testgslrun
This should print:
$ J0(5) = -1.775967713143382900e-001
Done!! Happy Computing.
#C #GNU #GSL #computing #programming
No comments:
Post a Comment