[R-SIG-Mac] Compiling packages with specific gcc

Simon Urbanek simon.urbanek at r-project.org
Wed May 6 11:13:36 CEST 2009


Steve,

On May 5, 2009, at 9:03 PM, Steve Lianoglou wrote:

> Thanks Duncan & Kasper, I've been able to squeeze out of my  
> problem ...
>
> Duncan:
>
>> You can pass configure args with the configure.args parameter to  
>> install.packages.  I'm not sure how many you need to set, but  
>> you'll likely need to set CC, CPP, CXX, F77, FC, OBJC, and maybe  
>> some of the associated flags.  You can see the list using "R CMD  
>> config" in the console.
>
> The R CMD config was the trick. I actually  put set those flags in  
> my ~/.R/Makevars-PLATFORM file, as it seems the build step is  
> picking these up so I don't have to pass them into the  
> configure.args param. For the record, since I'm on a first  
> generation MBP, the name of that file is "Makevars-i386-apple- 
> darwin8.11.1", and it looks like:
>
> CC=/usr/bin/gcc
> CPP=/usr/bin/cpp
> CXX=/usr/bin/g++
> CXXCPP=/usr/bin/cpp
> OBJC=/usr/bin/gcc
>
> Kasper:
>
>> You will want to recompile R with the new compiler. Then, whenever  
>> you compile a package, it will use the same compiler as R was  
>> compiled with.
>
> Thanks for the preemptive warning. On the computer where I'm having  
> this problem, R is actually installed from the official cran  
> installer, so I just needed to set it to use the apple gcc by default.
>
> I have to assume that this R was also built w/ Apple's gcc, so  
> perhaps R doesn't use the same compiler by default, as you suggest?  
> I'm not sure.
>

R uses the Apple compiler, but I'm not hard-coding the full path. In  
your case apparently your PATH has /usr/local/bin before the system  
paths, so it overrides the default. Another (simpler?) way to solve  
this is to simply move /usr/local/bin at the end of your PATH  
(recommended) and all should be well without changing any config files.


>> Mixing compilers might be possible using the hints from Duncan, but  
>> I am pretty sure it is discouraged.
>>
>> In the past Simon has discouraged use of the HPC compilers. I don't  
>> remember the reasons, but I respect the source of the  
>> information :) He knows way more about mac compilers than I do. Of  
>> course, this was a while back and things might have changed.
>
> Yeah, I'd trust that source of information as well :-)
>
> This kind of leads me into another related question, then. So, I  
> actually d/l'd the HPC compiler so I can compile w/ -fopenmp (to use  
> OpenMP for some easy parallelization).

You can use -fopenmp with Apple's compilers as well, just make sure  
you make the gcc-4.2 compilers the default (sudo gcc_select 4.2 if you  
have gcc_spect on your system, otherwise change the symlinks like ln - 
sf gcc-4.2 /usr/bin/gcc etc. - or specify them directly as you did).  
Apple's gcc-4.2 compilers are supported by the CRAN binary.


> Does this mean that I shouldn't do that w/ a vanilla R install and  
> perhaps recompile R from source w/ the HPC compiler? And if Simon  
> doesn't like using the HPC compiler, then should we stay away from  
> this in general?
>

In general, yes. As you have seen yourself the HPC compilers are not  
complete, so they cannot build universal binaries. Also they don't use  
Apple's driver, so all Apple-specific flags will fail. I didn't check  
the last HPC release, but before they were partially broken causing  
miscompilations, included wrong binaries (i.e. even the compiler for  
Tiger would include symbols for Leopard so the binary would not work),  
etc. I was trying to contact the maintainer a few times, but without  
avail, so I don't think it's well supported, either.

Cheers,
Simon



More information about the R-SIG-Mac mailing list