Setup


Please Note: 
  1. These instructions are very old (as of 2024). 
  2. Better methods are available now, such as the C/C++ extension to VSCode, which can be setup with GSL using vcpkg.

Please Note: 
  1. I have updated these instructions to describe a new method of setting up numerical analysis on Windows that is simpler than the old one. The older method that used Cygwin and Code::Blocks can be found here

  1. The target audience for these instructions are inexperienced users (noobs with some basic knowledge of C programming) who need to use the Microsoft Windows operating system. Setup for Linux operating systems is fairly straightforward, and should not require elaboration for experienced Linux users. See this link and this video, for instance. 

  1. The instructions given below involve using Code::Blocks and a standalone GSL library. If you need to use another IDE like Visual Studio, there are similar instructions at this website.

Summary:

On this page, I will provide instructions to set up C programming on Microsoft Windows with the Code::Blocks and the GNU Scientific Libraries in order to perform numerical analysis. There are 3 major steps, each being a collection of tasks that need to be performed in order to get everything up and running.

Glossary of Terms:

C-Compiler: Software that translates your C-program into machine language that the computer can execute.

Dynamically Linked Libraries (DLL):  Functions written by someone else that you can call in your C-program.

Header Files: Files containing definitions of C-functions. Often associated with DLLs.

Linking: Connecting your program to a DLL.

GNU Scientific Library (GSL): A set of Open Source Numerical and Scientific DLLs.

Code::Blocks (IDE): An IDE (Integrated Development Environment) that makes C-programming easier and compiling/linking automatic.

Introduction:

Before starting C programming on Windows, a C-compiler needs to be installed.  A compiler is a program that converts C code into executable machine code. There are several C compilers for windows. Some of them are proprietary and may require purchase, and others are FOSS, i.e. free and open source. Proprietary compilers include Microsoft Visual Studio or Intel® oneAPI DPC++/C++ Compiler. FOSS compilers include the GNU C compiler of GCC, the Gnu Compiler Collection, or the newer CLANG compiler. If in doubt, stick to GCC.

Once a compiler is installed, dynamically linked libraries (DLLs) of numerical routines should to be installed, so that their header files and functions can be used in C-programs through the process of linking. Proprietary libraries include Numerical Recipes, and FOSS libraries include GSL, the GNU Scientific Library.  For a brief introduction to the GSL library, see this website. Also, there is good background material on GSL out there, such as this book by Jose M. Garrido, as well as the very well-written GSL library documentation.

In addition to compilers and DLLs, it's a good idea to have an Integrated Development Environment, or IDE. An IDE is a suite of programs that developers need, combined into one convenient package, usually with a graphical user interface. These programs include a text editor, linker, project management, and often a compiler. The instructions below can be readily adapted to most IDEs. However, I shall provide explicit instructions for Code::Blocks, a Simple IDE for C/C++/FORTRAN that is ideal for beginners. 

Brief Instructions:

https://www.fosshub.com/Code-Blocks.html

Be sure to download "Code Blocks Windows 64 bit (including compiler)"

https://github.com/hariseldon99/GSL-WIN64

Go to the "Releases" section and download the latest release, which will be the .EXE file.

Ignore any warnings or danger messages from antivirus  or malware detection software. They're all false positives.

Congratulations! Code::Blocks is now ready for C-Programming with the GNU Scientific Library!

Detailed Step-by-step Instructions:


codeblocks-20.03mingw-setup.exe (Note that your version number may be newer than 20.03)

That way, you can download and install the IDE and the GCC C-compiler together


 Click here to download the GSL installer (it is the file ending in .EXE; always download the newest version), or click on the "Download GNU Scientific Library" icon above.


3. Start Code::Blocks. Once the IDE screen loads, you have to configure Code::Blocks to link the GSL libraries for your programs just after compilation. Follow the instructions below. Note that you only have to do this step once, not every time you start Code::Blocks.

'C:\Program Files\GSL-WIN64\gsl-2.7.1\include'   (Note that your GSL version number may be newer than 2.7.1).  

'C:\Program Files\GSL-WIN64\gsl-2.7.1\lib' (Note that your GSL version number may be newer than 2.7.1). 

There are two libraries that have been installed as Dynamically Linked Libraries, or .dll files., 'libgsl.dll.a' (the main GSL library) and 'libgslcblas.dll.a', which is the library of Linear Algebra routines, coded according to the BLAS standard. See the 'Miscellaneous' section below for details. For now, proceed to the bullet point below.

Congratulations! Now, you're all set to use Code::Blocks and the GNU Scientific Library for your computational work!

Testing:

Now we make sure that the installation and configurations are working properly. In order to do so, we shall write the following simple C programs using Code::Blocks, compile and run them. The first program is a simple "Hello World" code, and the second is a more sophisticated piece of C code that uses the GSL library.

3. In the new blank file, type in (or copy-paste) the code below (a simple "Hello World" program in C), and save it to a file named 'hello.c' (Click on "File --> Save file as" from the top menu bar).

4. Click on "Build" --> "Build and Run" on the top menu bar as shown in the screenshot below. If everything was installed and configured correctly, the build should succeed, a terminal should pop up, and the code should execute there.

Miscellaneous: