[Rd] problem customizing CXXFLAGS in Windows

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Apr 18 19:41:36 CEST 2008


On Fri, 18 Apr 2008, Ian Fiske wrote:

> Hi all,
>
> I am running R 2.6.2 in Windows XP with Rtools 2.7 and am trying to compile
> a shared library in Windows with customized level of optimization.
> Specifically, I would like to have "-O3 -funroll-loops" as flags when I run
> "R CMD SHLIB ***.cc" to speed the program for my simulations.
>
> I have read through the documentation and have tried adding the line
>
> PKG_CXXFLAGS = -O3 -funroll-loops
>
> in my Makevars in my package's src directory.  However, this places the
> flags before the -O2 flag, thereby overriding it.

I presume you meant the opposite -- 'it' refers to its immediate 
antecdent, 'the -O2 flag', which overrides not is overridden?  That is, 
the flags are processed from left to right and later settings win.

> I have also tried creating a config.site file in R_HOME/etc, but that 
> seems to be ignored.

What gave you the idea that would be relevant?  I don't see it in any of 
the manuals.

> I found a possible solution at
> http://tolstoy.newcastle.edu.au/R/e2/devel/07/03/2520.html.  However, when I
> use this suggestion, I get errors that R.h cannot be found.
>
> Please note that I do not plan to submit this package to CRAN or to other
> users with the modified flags, but I just need to set them on my machine to
> speed up simulations for testing, etc.

>From the R-admin manual:

'Package-specific compilation flags can be overridden or added to using 
the personal file $HOME/.R/Makevars.win, or if that does not exist, 
$HOME/.R/Makevars. (See the rw-FAQ for the meaning of $HOME.) For the 
record, the order of precedence is (last wins)

     * MakeDll and MkRules
     * src/Makevars.win if it exists, otherwise src/Makevars
     * $HOME/.R/Makevars.win if it exists, otherwise $HOME/.R/Makevars.
     * src/Makefile.win if present causes all but the last of the above to
       be ignored.
'


So you can set CXXFLAGS in src/Makevars.win and that will override the 
system's values.  Or you could change the system setting to -O3 in
MakeDll -- it is -O3 for C and Fortran, but -O2 for C++ (which R itself 
does not use) because -O3 for C++ used to be problematic (with gcc 3.4.5, 
not the current version).

I think the URL you give is too old -- it probably preceeds the corrected 
separation of CPPFLAGS and C[XX]FLAGS.  The rule is (from MkRules)

.cc.o:
         $(CXX) $(CPPFLAGS) $($*-CPPFLAGS) $(CXXFLAGS) $($*-CXXFLAGS) -c $< 
-o $@

and so CPPFLAGS should contain include paths, and CXXFLAGS optimization 
levels.

I've just taken a C++-using package and added

CXXFLAGS=-O3 -funroll-loops

to its Makevars.  All the headers were found, and that was the 
optimization level used.


> I appreciate any suggestions,
> Ian

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list