$ ./testgslrun
This should print:
$ J0(5) = -1.775967713143382900e-001
Done!! Happy Computing.
#C #GNU #GSL #computing #programming
Random thoughts punctuated with periods of silence. Opinions, comments, and expressions are personal and should not be associated with my employer.
$ ./testgslrun
This should print:
$ J0(5) = -1.775967713143382900e-001
Done!! Happy Computing.
#C #GNU #GSL #computing #programming
I often find that students are struggling to install a compiler for C and GNU Scientific Library (GSL) on their MS Windows machines. Sometimes Windows can behave weirdly while you try to install these tools. This happens mostly when you have installed and uninstalled lots of programs and packages.
Here is a step-by-step guide to install 1) a compiler for C and 2) GSL on your Windows machine.
Installation of MinGW on Windows 10
1. MinGW is a native Windows port of the GNU Compiler Collection (GCC). Download the MinGW installer from SourceForge:
https://sourceforge.net/projects/mingw/
2. Run the installer and follow the instructions on the screen.
3. The installer will install the MinGW installation manager. This is used for installing MinGW and to uninstall MinGW.
4. Run the installation manager. To start with we will install the basic setup.
Select basic setup on the left-hand pane.
On the righthand pane for the package list, select each package one by one and mark those for installation (Right-click > Mark for Installation).
Once all the packages are marked, install those: Installation > Apply Changes
5. Installation may take some time. Note that apart from MinGW, this process will also install MSYS. MSYS is a bash shell that we will use while compiling and running C codes.
6. On successful installation you may have the following directory structure:
C:\MinGW
Within this folder, you will find the MSYS subfolder. Find the msys.bat file. For example, this may be at: C:\MinGW\msys\1.0\msys.bat
Run this batch file (double-click) to get the bash shell. You can create a shortcut for this batch file and keep it at a suitable location, like the desktop.
7. Check MinGW installation by running a simple C code. For example, here is a
code named as test.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
8. To compile the code, you have to be in the folder with the code. Use cd to reach the appropriate folder. Note that we are now working in Bash shell (not in the Windows default command prompt). Therefore, in the pathname, we have to use / in place of \
9. Compile the code:
$ gcc test.c -o testrun
10. Run the code
$ ./testrun
If everything works fine, the program will print:
$ Hello, world!
Installation of GSL on Windows 10
1. You must install MinGW with MSYS before installing GSL.
2. Download GSL:
https://www.gnu.org/software/gsl/
3. Place the downloaded compressed file (named like: gsl-latest.tar.gz) in the MinGW folder.
4. Start MSYS. We will now use MSYS for all the subsequent work.
5. cd to the appropriate folder and extract the files:
$ tar xzf gsl-latest.tar.gz
6. The files will be placed in a newly created folder, for example, gsl-2.6
7. Move to that newly created folder:
$ cd gsl-2.6
8. Configure, make, and install GSL:
$ ./configure
$ make
$ make install
Each of these steps takes some time. Wait for the completion of each step before executing the next.
9. Upon completion of installation you should find the GSL lib and include folders inside msys folder. For example:
C:\MinGW\msys\1.0\local\include
C:\MinGW\msys\1.0\local\lib
10. Compile and run a C code that uses GSL. Again, we will use MSYS to compile and run the code. For example, here is the code for testgsl.c:
#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;
}
11. To compile:
$ gcc -I/usr/local/include -L/usr/local/lib testgsl.c -lgsl -o testgslrun
(Note that depending upon how MinGW and GSL have been installed, we may not have to include -I/usr/local/include -L/usr/local/lib in the command for compilation.)
12. Run the compiled code:
$ ./testgslrun
This should print:
$ J0(5) = -1.775967713143382900e-001
Done!! Happy Computing.
#C #programming #GSL #computing #compiler #gcc
oomfies solve this pic.twitter.com/0RO5zTJjKk— #em 𖤐 (@jik99k) July 28, 2019