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.
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 http://www.msys2.org
. 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
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: https://github.com/msys2/msys2/wiki
Download `gsl-latest.tar.gz` from ftp://ftp.gnu.org/gnu/gsl
(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
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 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.
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.