[R-pkg-devel] Checking for C++11
Dirk Eddelbuettel
edd at debian.org
Mon Nov 16 13:56:27 CET 2015
On 16 November 2015 at 13:07, Marvin Wright wrote:
| 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.
Yup. One of the things I dislike the about current CRAN checks. GNU Make *is*
a standard, but we are not allowed to use it unless we use the GNUMakefile
name (which is ugly), or declare a 'SystemRequirements: GNU make'.
So I would not use this.
| 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
Obviously not good as it throws an error.
| Any other ideas how to check? Or is one of the versions above OK on CRAN?
Look eg at RcppTOML which includes/provides the cpptoml.h header which is
real C++11. There I just do (in DESCRIPTION)
SystemRequirements: A C++11 compiler. Version 4.6.* of g++ (as currently in
Rtools) is insufficient; versions 4.8.*, 4.9.* or later will be fine.
and (in src/Makevars)
## This is a C++11 package
CXX_STD = CXX11
Then CRAN takes care of things -- see the status at
https://cran.rstudio.com/web/checks/check_results_RcppTOML.html
which generally builds fine (and where I just noticed the Mavericks error --
ick. Anybody with a Mavericks box who can help by poking around ?)
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the R-package-devel
mailing list