[R-pkg-devel] Checking for C++11

Duncan Murdoch murdoch.duncan at gmail.com
Mon Nov 16 13:44:10 CET 2015

On 16/11/2015 7:07 AM, Marvin Wright wrote:
> Dear all,
> I would like to check for C++11 support in a package. The package requires gcc >= 4.7 or clang >= 3.0. Windows is handled differently in Makevars.win. I tried two approaches in Makevars so far, but both give warnings in CRAN checks.
> Approach 1:
> ## Check for gcc >= 4.7
> ifeq ($(shell basename $(CC)),gcc)
> GCC_VER := $(shell gcc -dumpversion)
> GCC_MAJOR := $(shell gcc -dumpversion | cut -f1-2 -d.)
> GCC_OK := $(shell echo $(GCC_MAJOR) \>= 4.7 | bc )
> ifneq ($(GCC_OK),1)
>    $(error Error: gcc >= 4.7 required, version $(GCC_VER) installed. Please update gcc.)
> endif
> endif
> Works quite well but a warning in check —as-cran:
>> Found the following file(s) containing GNU extensions:
>> src/Makevars
>> Portable Makefiles do not use GNU extensions such as +=, :=, $(shell),
>> $(wildcard), ifeq ... endif. See section ‘Writing portable packages’ in
>> the ‘Writing R Extensions’ manual.
> Approach 2:
> Use std=c++11 flag instead of CXX_STD = CXX11, which should work on gcc >=4.7 and throw an error on earlier versions.
> This time in check —as-cran:
>> Non-portable flags in variable 'PKG_CPPFLAGS':
>> -std=c++11
> Any other ideas how to check? Or is one of the versions above OK on CRAN?

A better approach may be to check for features rather than versions by 
just using them.  Put in tests that fail if the features you need are 
not there, and put something like "C++11" into your DESCRIPTION file 
SystemRequirements field to tell people why they're failing (as well as 
comments in the source).

Duncan Murdoch

More information about the R-package-devel mailing list