Author Topic: Using the GSL-GNU scientific library in Windows with Code::Blocks  (Read 229 times)

Offline cadalso

  • Single posting newcomer
  • *
  • Posts: 1
The GSL-GNU scientific library can be compiled under Windows and linked to your applications using Code::Blocks. The following instructions are based on the 32 bit MingGW compiler. I did not try to use the 64 bit compiler. I have linked the GSL-GNU library statically. I have not tried dynamic linking.
In a nutshell the process consists of three steps: 1) installing MinGW using MSYS, 2) compile GSL-GNU using MSYS-MinGW, 3) configure Code::Blocks to use the MinGW compiler and link to the compiled GSL-GNU library.

1. Install MSYS

Download and install MSYS including the mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++ and msys-base packages in the basic setup. MSYS can be obtained from

2. Compile GSL-GNU using MingGW under MSYS

Download the latest version of GSL-GNU (named gsl.latest.tar.gz) from the webpage

Copy this file into the root directory of MSYS. In my computer the root directory is


Please note that user is my username in Windows. The username will vary depending on your local installation.

Open MSYS by navigating to the folder


and doing a double click to the file msys.bat. The MSYS command window opens. Type the following commands to unzip and compile the GSL-GNU library:

Code: [Select]
tar xf gsl*
cd gsl-2.4
./configure --prefix=C:/MinGW
make install

Compilation takes a while. I have assumed that the number version of GNU-GSL is 2.4 although this will vary if you have downloaded a different version of the library. Verify the number of your local installation. If you have successfully completed this step you can now link the GNU-GSL library to your programs.

You can test your local installation by compiling the following example program, which is included with the GNU-GSL library ( Create a program with the name bessel.cpp and write it to the MSYS root directory. The code is

Code: [Select]
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>

main (void)
  double x = 5.0;
  double y = gsl_sf_bessel_J0 (x);
  printf ("J0(%g) = %.18e\n", x, y);
  return 0;

Test your GNU-GSL by typing the following commands into the MSYS command window.

Code: [Select]
mingw32-gcc -Wall -I/usr/local/include -c bessel.cpp
mingw32-gcc -L/usr/local/lib -o bessel.exe bessel.o -llibgsl -llibgslcblas -lm

Note that the compiler is instructed to find the GNU-GSL header files in the /usr/local/include folder and link the library in /usr/local/lib. These paths are relative to your local MSYS installation. If everything is fine the compiler creates the executable file bessel.exe in the MSYS root directory. Note also that I have not used Code::Blocks up to know.

3. Configure Code::Blocks

Install Code::Block with the MinGW compiler. Go to the Settings > Compiler menu of Code::Blocks. In the Toolchains executables tab the MinGW compiler has to be selected. In my computer the Compiler's instalation directory is C:\Program Files (x86)\CodeBlocks\MinGW.

Tell Code::Blocks where the GNU-GSL header files are. Go to Settings > Compiler menu. Go to the tab Search directories > Compiler, and add the path C:\MinGW\include.

Tell Code::Blocks where the GNU-GSL library is. Go to Settings > Compiler menu. Go to the tab Search directories > Linker settings, and add the path C:\MinGW\lib.

Tell the linker where the compiled library is. Go to Settings > Compiler menu. Go to the tab Linker settings, and add the paths C:\MinGW\lib\libgsl.a and C:\MinGW\lib\libgslcblas.a.

Now you can open the bessel.cpp program in Code::Blocks and built it to test your installation.

Offline sodev

  • Almost regular
  • **
  • Posts: 141
Re: Using the GSL-GNU scientific library in Windows with Code::Blocks
« Reply #1 on: May 07, 2018, 09:46:00 am »
Don't compile the library with the msys2 mingw compiler but the application with the codeblocks mingw compiler, this is asking for a lot of trouble.

Also don't specify link libraries with an absolute path, just use the name, without lib and without extension.