17

I'm trying to install the gsl package for R, which I understand is simply a wrapper around the GSL, under OSX Mavericks. I've tried the obvious:

> install.packages('gsl')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)

   package ‘gsl’ is available as a source package but not as a binary

Warning in install.packages :
  package ‘gsl’ is not available (for R version 3.1.0)

So I ran

> install.packages('gsl',type = 'source')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/gsl_1.9-10.tar.gz'
Content type 'application/x-gzip' length 342803 bytes (334 Kb)
opened URL
==================================================
downloaded 334 Kb

* installing *source* package ‘gsl’ ...
** package ‘gsl’ successfully unpacked and MD5 sums checked
checking for gsl-config... no
configure: error: gsl-config not found, is GSL installed?
ERROR: configuration failed for package ‘gsl’
* removing ‘/Users/myusername/Library/R/3.1/library/gsl’
Warning in install.packages :
  installation of package ‘gsl’ had non-zero exit status

No GSL install. D'oh! So I install GSL via Homebrew:

~  brew install gsl
==> Downloading http://ftpmirror.gnu.org/gsl/gsl-1.15.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/gsl/1.15
==> make
==> make install
  /usr/local/Cellar/gsl/1.15: 239 files, 6.7M, built in 101 seconds

Try to install the R package again:

> install.packages('gsl',type = 'source')
Installing package into ‘/Users/myusername/Library/R/3.1/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/gsl_1.9-10.tar.gz'
Content type 'application/x-gzip' length 342803 bytes (334 Kb)
opened URL
==================================================
downloaded 334 Kb

* installing *source* package ‘gsl’ ...
** package ‘gsl’ successfully unpacked and MD5 sums checked
checking for gsl-config... /usr/local/bin/gsl-config
checking if GSL version >= 1.12... checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
configure: error: Need GSL version >= 1.12
ERROR: configuration failed for package ‘gsl’
* removing ‘/Users/myusername/Library/R/3.1/library/gsl’
Warning in install.packages :
  installation of package ‘gsl’ had non-zero exit status

I'm obviously going about this the wrong way but am unsure about where exactly the problem lies.

RoyalTS
  • 9,545
  • 12
  • 60
  • 101
  • 2
    I'm having this exact same problem. Mac OS 10.9.4, gcc 4.2.1, R 3.1.1, and GSL 1.16 as downloaded from Homebrew. Also, the example program in the docs (http://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html#An-Example-Program) compiles without a problem (although I have no clue how to run/test it because I know nothing about C). – shadowtalker Sep 28 '14 at 20:25
  • @RoyalTS. You appear not to have the GSL package (not the R-package gsl) installed in a place where the r-package expectes to find it. (http://www.gnu.org/software/gsl/) – IRTFM Sep 29 '14 at 17:24
  • 1
    @BondedDust I had installed it via homebrew and could run `gsl-config` from the command line without problems. I also tried uninstalling the homebrew version and building it from scratch but to no avail. I get the same error message. Where does the package expect to find the GSL and how can I point to the location it's actually in during install? – RoyalTS Sep 29 '14 at 18:07
  • I'm not running Mavericks or homebrew but I have read in some pages that you might patch this together with `launchctl setenv PATH "/usr/local/bin:$PATH"` run at a terminal session. – IRTFM Sep 30 '14 at 02:49
  • I think that may have down the trick, though only with a lot of additional duct tape. If you don't mind I'd put the entire procedure in an answer and see if it works for other people as well. – RoyalTS Sep 30 '14 at 10:46
  • @ssdecontrol can you try out the solution below and see if it works for you? For bonus points you could skip steps 1 and 2 and see if that works. That way we'd know if building the GSL from source is necessary out if homebrew does the trick as well. – RoyalTS Sep 30 '14 at 21:28

7 Answers7

19

I was able to get things working (OS X Yosemite 10.10, R 3.1.1, gsl 1.16, gsl R package 1.9-10) with standard brew-installed R and gsl by manually prefixing CFLAGS and LDFLAGS with the output from gsl-config --cflags and gsl-config --libs respectively.

The following:

CFLAGS="-I/usr/local/opt/gsl/include" LDFLAGS="-L/usr/local/opt/gsl/lib -lgsl -lgslcblas" R
...
> install.packages("gsl")

worked for me.

Note that gsl-config lists the direct path to my Cellar, the paths above are brew symlinks.

Andy
  • 354
  • 2
  • 4
  • 10
    Hi, I initially did not understand your solution (`...`, where to set the flags etc.), but finally figured it out (I guess): Running `gsl-config --cflags` gives (for me on 10.11) `-I/usr/local/include` and running `gsl-config --libs` gives `-L/usr/local/lib -lgsl -lgslcblas`. Hence I start R (from the terminal) with `CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib -lgsl -lgslcblas" R`. Then `install.packages("gsl")` works. Thought this might be helpful to others (less tech-savvy) to mention. – Marius Hofert Oct 22 '15 at 10:56
  • comment from @MariusHofert worked for me, instructions slightly easier to follow but parent answer still correct – Achekroud Mar 18 '17 at 22:35
14

For Mac, just run:

brew install gsl

then install the package in r

jackexu
  • 141
  • 1
  • 2
9

I finally got this to work though I'm not sure which parts of the following are absolutely essential. Here's a step-by-step list of instructions:

(steps in parentheses may be optional. Perhaps the whole thing works with homebrew)

  1. (download the latest version of the GSL from http://ftp.gnu.org/gnu/gsl/ (as of this writing the file to get is gsl-1.16.tar.gz))
  2. (open up a terminal window, untar the file, cd into the directory and then run ./configure, make and make install)
  3. download the sources to the R package from http://cran.r-project.org/web/packages/gsl/index.html
  4. open up a terminal window and run launchctl setenv PATH "/usr/local/bin:$PATH"
  5. in the same terminal window, build the R package (I couldn't get this to work from within R) by untar'ing the file just downloaded, cding into the directory and then running R CMD build ./gsl and R CMD INSTALL gsl_1.9-10.tar.gz
RoyalTS
  • 9,545
  • 12
  • 60
  • 101
  • 1
    I'll try this when I get a chance tomorrow. Out of curiosity, what does `launchctl setenv` do that `export` doesn't? – shadowtalker Sep 30 '14 at 22:44
  • @BondedDust is probably in a better position to answer that question. – RoyalTS Oct 01 '14 at 07:19
  • Doesn't work without steps 1 and 2. I still get `configure: error: Need GSL version >= 1.12`. – shadowtalker Oct 01 '14 at 12:45
  • 1
    Just tried it. That's a negative. I think it's a bug with the R package: when you install it, there are a bunch of lines like `checking for gsl-config... /usr/local/bin/gsl-config` that include a check and the result. However the line `checking if GSL version >= 1.12... checking for gcc... gcc` seems to "skip" the result, so I'm wondering if the check is not properly conducted, or something changed in GSL itself since version 1.12 that makes the check fail. – shadowtalker Oct 01 '14 at 12:49
  • I'm e-mailing Robin Hankin about it now, with a link to this question. – shadowtalker Oct 01 '14 at 12:51
  • My answer above was pieced together from @BondedDust's suggestions and stuff Robin Hankin told me via email. He's aware of the question but can't reproduce the problem. But I guess it doesn't hurt to ask. – RoyalTS Oct 01 '14 at 12:53
  • And for reference, this also fails with GSL 1.12. Same problem. – shadowtalker Oct 01 '14 at 13:04
  • Yeah, the problem very much seems to be that the package simply can't find the local gsl install, not that the version check fails. – RoyalTS Oct 01 '14 at 13:05
  • @ssdecontrol One more thing: Did you uninstall the homebrew version before building your own? That's the only thing that I did in addition to what's in the answer above. – RoyalTS Oct 03 '14 at 12:50
  • yes. I'm also not sure it has to do with finding GSL, because before GSL was installed the check failed sooner. – shadowtalker Oct 03 '14 at 14:02
  • I do a daily `brew update && brew upgrade` but I've never installed `gsl` before. I just did a `brew install gsl` and a `install.packages('gsl', type="source")` and it installed and loaded without a hitch. R 3.1.1 OS X Mavericks. You might want to try a `brew doctor` to see if that fixes anything. – hrbrmstr Oct 04 '14 at 00:51
4

Note to self: On Debian, to fix

checking for gsl-config... no
configure: error: gsl-config not found, is GSL installed?

I needed to

sudo apt-get install libgsl-dev

Note that the package name on Debian is not gsl-devel as elsewhere. Sigh.

Art
  • 73
  • 4
  • For Ubuntu 16.04, R version 3.6.3 (2020-02-29), installing libgsl-dev solve the error you point out. But another error is raised during installation : `configure: error: Need GSL version >= 1.16` `ERROR: configuration failed for package ‘gsl’` – Yoann Pageaud Sep 21 '21 at 08:42
2

I believe that others will find your steps successful and I think they do need to be done in that order. The build of gsl from source does need to be done after adding the homebrew default directory to the path. If you had used the binary, it was built on a CRAN machine that was able to find the (external) GSL package in the expected directy (which is not the default for homebreww installations. You might have succeeded with `install.packages('gsl_1.9-10.tar.gz', repo=NULL, type="source") if the source package were in your working directory (or add the full path/name as the first argument.) Just as with using Terminal, if you click-hold-drag a file to the R console, you will get a text entry of the full path/name.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
1

gsl-config in included with the gsl-devel package, try installing that. After that it should work

Bastiaan Quast
  • 2,802
  • 1
  • 24
  • 50
0

On OS X Mavericks at least, after installing gsl via brew install gsl, the gsl-config --prefix yields /usr/local/Cellar/gsl/1.16. However, many applications/libraries like gsll for Common Lisp (in my case) expect /usr/local/Cellar/gsl/1.16/lib instead. In my case, the super lazy (long-term unacceptable) solution was just to symlink the libs from /usr/local/Cellar/gsl/1.16/lib into /usr/local/Cellar/gsl/1.16 and all was well. Hope this helps.

Joe
  • 965
  • 11
  • 16