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 MSYSDownload 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
http://www.mingw.org/wiki/MSYS2. Compile GSL-GNU using MingGW under MSYSDownload the latest version of GSL-GNU (named
gsl.latest.tar.gz) from the webpage
ftp://ftp.gnu.org/gnu/gsl/Copy this file into the root directory of MSYS. In my computer the root directory is
C:\MinGW\msys\1.0\home\userPlease note that
user is my username in Windows. The username will vary depending on your local installation.
Open MSYS by navigating to the folder
C:\MinGW\msys\1.0\ 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:
tar xf gsl*
cd gsl-2.4
./configure --prefix=C:/MinGW
make
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 (
https://www.gnu.org/software/gsl/doc/html/usage.html#an-example-program). Create a program with the name
bessel.cpp and write it to the MSYS root directory. The code is
#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;
}
Test your GNU-GSL by typing the following commands into the MSYS command window.
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::BlocksInstall 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.