Link error installing Rcpp "library not found for -lintl"

10,023

Solution 1

Apparently, libintl is part of the gettext package. I did the following, possibly redundant reinstall to make sure my copy was up-to-date:

$ brew install gettext
Warning: gettext-0.18.3.2 already installed
$ brew reinstall gettext
==> Reinstalling gettext 
==> Downloading http://ftpmirror.gnu.org/gettext/gettext-0.18.3.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/gettext-0.18.3.2.tar.gz
==> ./configure --prefix=/usr/local/Cellar/gettext/0.18.3.2 --with-included-gettext --with-included-glib --with-included-libcroco --with-included-libunistring --with-emac
==> make
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

OS X provides the BSD gettext library and some software gets confused if both are in the library path.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/gettext/lib
    CPPFLAGS: -I/usr/local/opt/gettext/include

It says in the above output that brew doesn't symlink the library, which might explain why install.packages can't find it. What did the trick was adding a library path into ~/.R/Makevars like so:

PKG_LIBS=-L/usr/local/Cellar/gettext/0.18.3.2/lib

Solution 2

This answer is to modify Giupo's answer as it contains a typo but I believe it is important enough to be more prominent than a comment. The solution is a very effective way to install the Rserve package from Homebrew without causing broader problems on OSX:

    flags="CPPFLAGS=-I/usr/local/opt/gettext/lib LDFLAGS=-L/usr/local/opt/gettext/include"
    install.packages('Rserve', configure.args=flags)

To reduce namespace pollution even more can wrap in local:

    local({
           flags="CPPFLAGS=-I/usr/local/opt/gettext/lib LDFLAGS=-L/usr/local/opt/gettext/include"
           install.packages('Rserve', configure.args=flags)})

Solution 3

I wanna add my 2 cents to the quest by suggesting a less intrusive (meaning: no files/env changes for the user bringing unwanted side-effects in the future)

Take note of LDFLAGS and CPPFLAGS by reinstalling gettext as @cbare did and pass them to install.packages (inside R) with the configure.args param:

flags="LDFLAGS=-L/usr/local/opt/gettext/lib CPPFLAGS=-I/usr/local/opt/gettext/include"
install.packages('Rcpp', configure.args=flags)

This should do the trick (it worked for me while struggling with the same problem installing Rserve).

Share:
10,023
cbare
Author by

cbare

Software engineer interested in data, machine-learning, natural-language-processing, and health-technology.

Updated on July 30, 2022

Comments

  • cbare
    cbare almost 2 years

    I just stumbled over a linker error when trying to install some R packages which have Rcpp as a dependency. My setup is Mac OS X 10.9.1 (Mavericks), R 3.0.2 installed by Homebrew. Here's the error output:

    > install.packages('Rcpp')
    trying URL 'http://cran.fhcrc.org/src/contrib/Rcpp_0.10.6.tar.gz'
    Content type 'application/x-gzip' length 1985569 bytes (1.9 Mb)
    opened URL
    ==================================================
    downloaded 1.9 Mb
    
    * installing *source* package ‘Rcpp’ ...
    ** package ‘Rcpp’ successfully unpacked and MD5 sums checked
    ** libs
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c Date.cpp -o Date.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c Module.cpp -o Module.o
    clang -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC   -c Rcpp_init.c -o Rcpp_init.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c Timer.cpp -o Timer.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c api.cpp -o api.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c attributes.cpp -o attributes.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c barrier.cpp -o barrier.o
    clang++ -I/usr/local/Cellar/r/3.0.2/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include    -fPIC  -g -O2  -c exceptions.cpp -o exceptions.o
    clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o Rcpp.so Date.o Module.o Rcpp_init.o Timer.o api.o attributes.o barrier.o exceptions.o -F/usr/local/Cellar/r/3.0.2/R.framework/.. -framework R -lintl -Wl,-framework -Wl,CoreFoundation
    ld: library not found for -lintl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 10 years
    That strikes me as a little unusual. Did you build R from source, or did you use Simon's binary?
  • cbare
    cbare over 10 years
    Installed R via homebrew.
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 10 years
    The official word is that is not supported. If you go that route, and things break, you get to keep both pieces. Maybe try the r-sig-mac list?
  • cbare
    cbare over 10 years
    Thanks, Dirk. For what it's worth, I ran into more issues further on (installing dplyr). Maybe I should stick with the binaries on CRAN.
  • cbare
    cbare over 10 years
    Reinstalled binary from cran. Installs went without a hitch. Thanks again.
  • Dirk Eddelbuettel
    Dirk Eddelbuettel over 10 years
    Nice!! It is sad that life is so messy for folks on OS X, but c'est la vie. On Linux, things just work. :)
  • Romain Francois
    Romain Francois over 10 years
    I don't understand why people install R from Homebrew on OSX. We even have daily binary builds of the devel version if we want. If you use that, things work. Where are the daily builds in linux ?
  • Kenton
    Kenton about 10 years
    Just a warning. This solution is nice but may cause problems if trying to reinstall R using home-brew!
  • Dominique
    Dominique about 10 years
    What's the problem with using Homebrew? Are you also against users building R by hand? It should "just work" just the same.
  • Chris Fonnesbeck
    Chris Fonnesbeck almost 10 years
    Why do some Linux users want to install R from apt-get? Same reason.
  • mcheema
    mcheema over 7 years
    Hopefully, anyone looking to use Homebrew will look at this solution as it works and with minimal side effects
  • mcheema
    mcheema over 7 years
    I tried editing earlier question but mysteriously had the edit rejected.
  • rien333
    rien333 over 6 years
    I don't get it, brew shows LDFLAGS: -L/usr/local/opt/gettext/lib CPPFLAGS: -I/usr/local/opt/gettext/include but you seem to have them interchanged?
  • Giupo
    Giupo about 6 years
    @rien333 you are absolutely right! Sorry for the late fix!
  • Giupo
    Giupo about 6 years
    If I did reject the edit, it wasn't my intention! Thank you for pointing out the typo.