I recently tried to install the topicmodels R package (v0.2-3) on my Mac that was running OS X Yosemite (v10.10.4 - 14E46) with Xcode (v6.4 - 6E35b). My R (v3.2.2) was installed using homebrew.

I ran the following command in my R console:


Only to be met with the following errors:

ctm.c:29:10: fatal error: 'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>
1 error generated.
make: *** [ctm.o] Error 1
fatal error: 'gsl/gsl_rng.h'

The topicmodels R package actually depends on the GNU scientific library (GSL). You can get this using homebrew:

brew install gsl

At the time of this writing, this version was stable 1.16 (bottled). But even after installing this, I still got the same error. After taking a closer look, at the include statements:

-I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include

I noticed this wasn’t actually including the gsl headers located at /usr/local/opt/gsl/include. A post about this exact same problem was made on stackoverflow. The solution was to include the following in ~/.R/Makevars:

LDFLAGS=-L/usr/local/opt/gsl/lib -lgsl -lgslcblas

More details on what a Makevars file is can be found here:

makevars is a make file that overrides the default make file generated by R (which is located at file.path(R.home("etc"), "Makeconf"))

Hadley Wickham in R packages

How this helps you if you run into the same problem!

For Centos Users

For those on Centos, you install gsl (if you have admin):

yum install gsl-devel

This will install the headers, by default into /usr/include/gsl.