[R-pkg-devel] SystemRequirements and .R/Makevars

Ramon Diaz-Uriarte rdiaz02 at gmail.com
Fri Jun 19 18:53:19 CEST 2015


Hi Dirk,




On Fri, 19-06-2015, at 15:04, Dirk Eddelbuettel <edd at debian.org> wrote:
> Hi Ramon,
>
> On 19 June 2015 at 12:01, Ramon Diaz-Uriarte wrote:
> | Some of my packages use
> | 
> | SystemRequirements: C++11
> | 
> | in the DESCRIPTION. But then .R/Makevars seems to be ignored (e.g., flags
> | such as -Wall or using clang) in all that concerns C++ (only CXX and
> | CXXFLAGS are ignored, not CC or CFLAGS). So I keep commenting that line for
> | normal development and uncommenting it for final checking before release.
> | 
> | 
> | I vaguely remember reading somewhere this is the way things work, but this
> | is not what I understand from reading again
> | http://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Using-C_002b_002b11-code.
> | 
> | After googling I have not been able to locate anything, and since I guess
> | it is probably common to use both C++11 and a custom .R/Makevars I think
> | something is wrong somewhere in my setup. But I have no idea what. I am
> | using Debian (a mix of testing and unstable), both with stock Debian R and
> | with custom built Rs.
>
> I settled pretty early on declaring this in src/Makevars only, partly for
> historical reason (as it is where we always set compiler flags) and partly
> because I found it to be consistent and reliabel.  Writing R Extensions
> offers an alternate, I forget the details.
>
> One tricky bit is that we now have several CXX* variables.  And because "code
> is documentation" I often do the following to remind myself of CXX1X:
>
>   edd at max:~$ grep ^CXX /etc/R/Makeconf 
>   CXX = g++
>   CXXCPP = $(CXX) -E
>   CXXFLAGS = -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g $(LTO)
>   CXXPICFLAGS = -fpic
>   CXX1X = g++
>   CXX1XFLAGS = -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g
>   CXX1XPICFLAGS = -fpic
>   CXX1XSTD =  -std=c++11

Aha! Thanks. I modified them slightly to try it out and have now in .R/Makevars


## If I want clang
# CC=clang
# CXX=clang++-libc++
# CXX1X=clang++-libc++

CFLAGS= -O3 -g0 -Wall -Wextra -pipe -pedantic -std=gnu99 

CXXFLAGS= -isystem /home/ramon/Sources/R-3.2.1-bioc-devel-68530/library/Rcpp/include  -g -O3 -Wall -Wextra -pipe -std=c++11
CXX1XFLAGS= -isystem /home/ramon/Sources/R-3.2.1-bioc-devel-68530/library/Rcpp/include -g -O3  -Wall -Wextra -pipe 
CXX1XSTD= -std=c++11
CXX1XPICFLAGS = -fpic

I added a src/Makevars to the package that contains only

CXX_STD = CXX11


and everything is working now. I can modify flags at will and change
compilers to make sure it works with clang.


>   edd at max:~$
>
> I my most recent C++11-only package I did
>
>   edd at max:~$ cat git/rcpptoml/src/Makevars 
>   
>   ## This is a C++11 package
>   CXX_STD = CXX11
>   
>   ## We need the header in inst/include, and a define
>   PKG_CPPFLAGS = -I../inst/include/ -DCPPTOML_USE_MAP
>
>   edd at max:~$
>
> which regroups both the the compiler choice, an include directive and a
> #define in one place.

Aha! I did not need those right now but it is great to know it is that
easy. 

>
> Hope this helps, Dirk

It certainly does.

Best,

R.

-- 
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-25
Facultad de Medicina
Universidad Autónoma de Madrid 
Arzobispo Morcillo, 4
28029 Madrid
Spain

Phone: +34-91-497-2412

Email: rdiaz02 at gmail.com
       ramon.diaz at iib.uam.es

http://ligarto.org/rdiaz



More information about the R-package-devel mailing list