Some Useful C Libraries
Learn about some external libraries that can greatly enhance C's power.
We'll cover the following
Since C is such a “small” language, you must typically rely on libraries and APIs for complex tasks (unless you code them up yourself).
Here is a short list of some common libraries that you might find useful:
- GLib
- GNU Scientific Library
- BLAS / LAPACK
- Apophenia
- GNUplot
We’ll go through them one by one, starting with GLib.
GLib
The GLib library contains many useful data structures and building blocks that we sort of get “for free” in languages like Matlab and Python—data structures like lists, hash tables (otherwise known as dictionaries), arrays, trees, etc.
Next up, we have GSL, which is used for complex calculations.
GSL
The GNU Scientific Library (GSL) provides a broad range of numerical and mathematical functions. If you want to do something in C that you have been doing in MATLAB, or Python/NumPy/SciPy, or R, then probably you will need to look at something like GSL for functions you need (or code them up yourself).
After GSL, we have the BLAS/LAPACK libraries for algebraic computations.
BLAS/LAPACK
The BLAS and LAPACK libraries are high-performance libraries for linear algebra. If you are dealing with large matrices and you have the need for speed, then probably you should look into using BLAS and LAPACK, it will probably be faster than GSL.
Apophenia
Statistical computations are also very important. For that we have Apophenia. The Apophenia library is an open source library for working with data sets, statistics, and statistical models.
The Apophenia library provides functions for dealing with data (reading it in, storing it in convenient data structures, and writing it to files). It also provides functions for dealing with data using the SQL database language. This allows you to perform searches on data, extract subsets of data, etc.
Apophenia has lots of functions to fit data to statistical models such as OLS models (ordinary least squares), it provides for statistical tests like t-tests, F-tests, and it includes models like logit, probit, and multinomial models. It also includes maximum likelihood methods, Bayesian updating, and resampling methods like bootstrapping.
Modeling with Data (book)
Apophenia is maintained by Ben Klemens, who also wrote a book Modeling With Data that makes use of Apophenia. You can buy the book or you can download it for free—the author makes it available on the website.
I highly recommend the book not only as a guide to using the Apophenia library, but more generally as a guide to how to use C on a daily basis for data analysis and modeling. Ben argues that really, C is not that much more of a pain in the neck than “higher-level” languages like Python and R, but C is way faster (in terms of execution speed). It’s worth a read.
The last on our list is GNUplot, which as the name suggests, is used to make graphs and figures.
GNUplot
GNUplot is not an external C library but in fact is a standalone program for making graphs and figures. I include it here because it is a popular UNIX tool that you will likely see in your C travels. The Apophenia library and the accompanying book “Modeling With Data” include lots of examples of using GNUplot to graphically visualize data, and fitted statistical models.
There is also good online documentation, tutorials and help and demos of GNUplot functionality. Anything you can do with Matlab, Python/Matplotlib, R, etc you can likely also do in GNUplot.
These libraries have allowed C to become much more flexible and diverse in its functionality. Another feature of C that makes it stand out is its ability to facilitate parallel programming. The next chapter deals with everything related to this approach to programming.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy