15

I have a new iMac and I'm trying to run code using the Rcpp library that has been working on both my old iMac and Macbook Pro without issue. I have tried everything I can't seem to figure out what the issue is.

Xcode 5.0 downloaded. Command line Tools then installed. R3.0.2 is installed. I downloaded a gcc compiler. When I type gcc in terminal - I get "clang:" - which is good, I think.

The error I get is copied below. Thanks in advance for any ideas and advice.

Error (in R console):
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include  -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include"    -fPIC  -mtune=core2 -g -O2  -c SBM-Ccode.cpp -o SBM-Ccode.o 
Error in sourceCpp("SBM-Ccode.cpp") : 
  Error 1 occurred building shared library.

WARNING: The tools required to build C++ code for R were not found.

Please install Command Line Tools for XCode (or equivalent).

/bin/sh: llvm-g++-4.2: command not found
make: *** [SBM-Ccode.o] Error 127
16
  • 1
    What version of Mac OS / XCode where you using, and what versions are you using right now? Commented Oct 21, 2013 at 20:35
  • You type gcc and you get clang:? That doesn't make much sense; gcc and clang are separate toolchains for compilation. XCode comes with an (old, but compatible) version of gcc for compilation; where did you get your new version of gcc? Are you able to run llvm-g++-4.2 (which should be the XCode version of g++) from the command line? Commented Oct 21, 2013 at 21:29
  • Kevin: I think R remembers g++-4.2.1 from its build. The OP states that he added clang to his sytem (via XCode 5.0). The question now is now how to tell R to use clang; see my answers and Romain's earlier answer. Commented Oct 21, 2013 at 21:51
  • I have CXX = llvm-g++-4.2 -arch x86_64 in the Makeconf file Dirk mentionned. This is an R installed right out of the binary from CRAN. Nothing fancy. Commented Oct 21, 2013 at 22:02
  • But apparently one must override it to make R work out of the box. I score one for my assertion that OS X ain't as easy as its fans make it out to be. And where do people get their Fortran compilers and libraries (needed for some CRAN packages) from? Homebrew? Commented Oct 21, 2013 at 22:05

3 Answers 3

18

I'm not sure what you mean by "I downloaded a gcc compiler". You don't need to download your own gcc. You can use either the default or use clang++ by having something like this in your ~/.R/Makevars file:

CC=clang
CXX=clang++
CXXFLAGS= -O3 -pedantic

What happens when you try devtools::has_devel:

> require(devtools)
> has_devel()
'/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD SHLIB foo.c

clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include    -fPIC  -mtune=core2 -g -O2  -c foo.c -o foo.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o foo.so foo.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
[1] TRUE

or Rcpp::evalCpp:

> require(Rcpp)
> evalCpp( "1+1")
[1] 2    
Sign up to request clarification or add additional context in comments.

5 Comments

When I do the first, I get the error: '/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD SHLIB foo.c llvm-gcc-4.2 -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c foo.c -o foo.o make: llvm-gcc-4.2: No such file or directory make: *** [foo.o] Error 1 Error: Command failed (1)
When I do the second, I get the same error as in my OP. llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -fPIC -mtune=core2 -g -O2 -c file1818236400cd.cpp -o file1818236400cd.o
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : Error 1 occurred building shared library. WARNING: The tools required to build C++ code for R were not found. Please install Command Line Tools for XCode (or equivalent). /bin/sh: llvm-g++-4.2: command not found make: *** [file1818236400cd.o] Error 127
Did you restart your R session? This should work for you; the fact that llvm-g++-4.2 is still being searched for is strange. In fact, clang is now the only compiler in XCode 5.0, so llvm-g++-4.2 is no longer available. This explains the somewhat strange error in the OP.
THANK YOU ALL! I restarted and things are now working. I really appreciate the help.
8

Quick guess:

  1. You are running the pre-built R binary which Simon built / CRAN provides.

  2. R stores its configuration options from its compile time, those influence its run-time.

  3. Check via the file $R_HOME/etc/Makeconf and look at CC and CXX.

  4. As Romain suggested, override CC and CXX via a file ~/.R/Makevars.

  5. Try again.

Edit: I just confirmed with a colleague who has the exact same issue on a Mac OS X which he just upgrades to XCode 5 -- one now needs to override CC and CXX as R was built with the previous version of XCode.

1 Comment

For 3, you can also use R CMD config CXX
5

A easier solution would be the following. You should soft link the llvm compiler, in the terminal type:

cd /usr/bin
sudo ln -fs clang llvm-gcc-4.2
sudo ln -fs clang++ llvm-g++-4.2

Note: This also works for mex in Matlab.

2 Comments

worked for me -- and a little less scary than editing the Makeconf
A similar solution worked for me: sudo ln -fs clang gcc-4.2; sudo ln -fs clang++ g++-4.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.