Page 1 of 1

gsl library

Posted: Tue Jan 08, 2019 1:00 am
by Walebepro

I have codelite v 12.0.4.

How do install and use GNU scientific library in codelite?

Please kindly assist.

Re: gsl library

Posted: Tue Jan 08, 2019 2:00 am
by LinusKer
You have to download the source, compile it, and then configure the project so that it finds the header files and the compiled library. In which step do you need assistance?

Re: gsl library

Posted: Tue Jan 08, 2019 5:09 pm
by Walebepro
Thank you very much.

Please advise how to compile the gsl library first.

Re: gsl library

Posted: Tue Jan 08, 2019 6:40 pm
by LinusKer
The GSL, as many other libraries, is prepared to be compiled by the typical toolchain of UNIX systems (bash, autoconf, autotools, make, gcc, etc), with few instructions that generate automatic makefiles and put all files in the proper place. In the directory where the source files have been downloaded you run

$ ./configure
$ make
$ make install

and that's it. (Well, essentially; `configure` can take different parameters).

If you are using Linux or a similar OS, that's all. If you are using Windows, the procedure is longer. If this is your case, I can give you detailed instructions.

Re: gsl library

Posted: Tue Jan 08, 2019 11:54 pm
by Walebepro
Thanks LinusKer.

I am using Windows. please advise.

Re: gsl library

Posted: Wed Jan 09, 2019 8:49 am
by LinusKer
There are two ways to compile a library for Windows:

1. Use the tools provided by a Windows C/C++ compiler (gcc for instance) and a Windows console. I successfully compiled wxWidgets 3.0 in this way, though I walked a long trial-and-error path. With wxWidgets 3.1 was a little easier.

2. Use the usual UNIX tools (ported to Windows). I compiled GSL 2.5 in this way and it worked perfectly fine. I recommend it, because you can reuse those UNIX tools in other library compilations or in other jobs.

So, I will explain the second way, which involves two steps: 1) Install the UNIX tools; 2) Use them to compile GSL.

Step 1:

The UNIX tools are provided by MSYS2 (it means "Minimal SYStem"; the "2" has to do with a previous MSYS, now obsolete). Download it from There are alternatives, but I think MSYS2 is best for our purposes.

MSYS2 will install three minimal UNIX subsystems, each with its corresponding package repository, and a console interface.

Download the self-install file `msys2-x86_64_.....exe` (or the one with `i868` in the name if you have a Windows of 32bits). Choose a short directory, like `C:\msys64`. You will find and entry `MSYS2 64bit` in the Windows start menu with subentries `MSYS2 MinGW 32-bit`, `MSYS2 MinGW 64-bit`, `MSYS2 MSYS`.

The entries start three almost identical consoles (except for the prompt), but they have behind different UNIX subsystems, with different paths. For instance, the included compiler `gcc` is different in the three subsystems. Running `gcc` in the console `MSYS`, it will produce a UNIX executable; the one in the `MinGW32` console will produce a 32 bits Windows executable; the one in the `MinGW64`, a 64 bits Windows executable. The last alternative is possibly what you want; let us assume so.

We also need to install packages that do not come with the initial MSYS2 installation. The package manager that comes with MSYS2 is called `pacman`. Use it from the MSYS console; from there you can install packages for the three subsystems. Run

Code: Select all

    $ pacman -Syuu

Close the console and open it again. Run the same command until it says there is nothing to update. Then do

Code: Select all

    $ pacman -S --needed base-devel

You can install the four packages one by one if you prefer. The switch `-S` is for install, and `--needed` is to skip the installation if the package is already installed. If you want to develop also for 32bit machines from your 64bit machine, then you also need to install the corresponding packages with `i686` instead of `x86_64`.

Add to the windows system path `C:\msys64\mingw64\bin` (or `C:\msys64\mingw32\bin` to give priority to the compiler that produces 32bit executables), so that you can use `gcc` directly from your working directory later. (You may already have a gcc compiler for Windows in your system; if you want to use it instead, forget this paragraph; for your information, on 2018-11-01, MSYS2 has installed gcc version 8.2.0 in the MinGW64 subsystem.)

For more information on MSYS2, see the MSYS2 Wiki:

Step 2:

Download `gsl-latest.tar.gz` from or (or one of the older versions therein, if you need to).
Put it in the `home/user` directory of the MSYS2 susbsystem (which corresponds to the Windows path `C:\msys64\home\user`).

Open the console of the MinGW64 susbsystem. (Again, assuming that you intend to produce 64bit executables; if you want 32bit ones, use the MinGW32 console). Run

Code: Select all

    $ tar -xf gsl-latest.tar.gz

This will "untar" the file to the subdirectory `gsl-2.5` (or similar name).

Code: Select all

    $ cd gsl-2.5
    $ mkdir build
    $ cd build
The last two instructions will make the result of the compilation go to a different directory from that of the sources, which is more clean, but not mandatory. Let's assume you do it.

Then you can proceed to the compilation itself with the UNIX tools. Run

Code: Select all

    $ ../configure --prefix=C:\Progs\gsl-2.5 --enable-shared
    $ make 
    $ make install  
The `--prefix` is the directory where we want to send the header files and the compiled libraries. It can be anything, provided there are no blanks, accented letters, etc).

The `--enable-shared` switch makes the compiler produce the dynamic (aka shared) libraries (.dll files). Without it, it will produce the static ones (.a files). You probably want to have both, so run the three commands twice, with and without the switch.

That's it. To compile your program using the library GSL you must specify in the compiling command the switch for the location of the include files `-IC:/Progs/gsl-2.5/include` and, in the linking, the switch for the location of the libraries `-LC:/Progs/gsl-2.5/lib` and then the actual linkage `-lgsl -lgslcblas`.

Let us know if it worked for you.


Re: gsl library

Posted: Wed Jan 09, 2019 11:33 pm
by Walebepro
Thank you LinusKer. I will give it a go and let you know.

Apologies i forgot to mention that my programming language of choice is C and not C++.