The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is a free open source library under the GNU General Public License.

 

Note: this tutorial has been tested on Ubuntu, Redhat and Mac OS.

 

Download: 

ftp://ftp.gnu.org/gnu/gsl/

wget ftp://ftp.gnu.org/gnu/gsl/gsl-*.*.tar.gz

*.* should be replaced by the version to be installed. Please check release history available at https://www.gnu.org/software/gsl/. You can also download here and unzip the program directly depending on the OS you are working with.

 

Place the file in your home directory and unpack the file with the following command:

tar -zxvf gsl-*.*.tar.gz

This will create a directory called gsl-*.* in your home directory. Change to this directory.

cd gsl-1.7

The next step is to configure the installation and tell the system where to install the files. Create a directory to install your gsl package, say “/home/yourname/gsl” with the following command

mkdir /home/yourname/gsl

Now configure the installation and tell it to use your new directory. This step may take a few minutes.

./configure --prefix=/home/yourname/gsl

If there are no errors, compile the library. This step will take several minutes.

make

Now it is necessary to check and test the library before actually installing it. This step will take some time.

make check

If there are no errors, go ahead and install the library with:

make install

Now we can write a test program to see if the library works. Create the following program and name it example.c

#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>

int
main (void)
{
    double x = 15.0;
    double y = gsl_sf_bessel_J0 (x);
    printf ("J0(%g) = %.18e/n", x, y);
    return 0;
}

Compile and link the program with the following commands (but use the correct path for your username):

gcc -Wall -I/home/yourname/gsl/include -c example.c
gcc -L/home/yourname/gsl/lib example.o -lgsl -lgslcblas -lm

Now run your program!

./a.out

 

Now that you have the GSL installed, you can remove the gsl-*.* directory that was created in your home directory.

 

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

For Linux/Unix based machines, a complete instruction is available at the installation page of gcc website.

For Mac users, there are more choices except for the one above (installing from source, gcc version 6.1 which can be replaced!):

1. Port Install:

sudo port install gcc6
sudo port select --list gcc
sudo port select --set gcc mp-gcc6

where the first line is for installation, second line for listing existing compilers by Macports and the last one is to select default gcc compiler. You can update Macports by:

sudo port selfupdate

2. Homebrew:

brew tap homebrew/versions
sudo brew install [flags] gcc6

Please use the following to check available flags:

sudo brew options gcc6

and use the following for checking available gcc versions:

sudo brew search gcc

You can update Macports by:

sudo brew update

For installation of Homebrew, please check MacPorts and Homebrew.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Here is command for replacing the default gcc compiler with the newest one.

cd /usr/local/bin
rm cc gcc g++ c++

where the directory should be replaced by the directory where default gcc is placed

Now run your program!

ln -s /usr/local/bin/gcc-6 cc
ln -s /usr/local/bin/gcc-6 cc
ln -s /usr/local/bin/g++-6 g++
ln -s /usr/local/bin/c++-6 c++

where the compilers (with directories) should be replaced by your new compilers.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Any comment or question is welcome.