[R-pkg-devel] Checking for C++11
wright at imbs.uni-luebeck.de
Mon Nov 16 16:45:10 CET 2015
Thanks, that helped. However, a user with gcc < 4.7 will still get cryptic errors.
I had another idea: I created a file src/AAA_check_cpp11.cpp, checking the preprocessor directive “__cplusplus”, see https://github.com/mnwright/ranger/blob/master/ranger-r-package/ranger/src/AAA_check_cpp11.cpp <https://github.com/mnwright/ranger/blob/master/ranger-r-package/ranger/src/AAA_check_cpp11.cpp>. This isn’t beautiful, but the error message is better and it’s fine on CRAN.
> On 16 Nov 2015, at 13:56, Dirk Eddelbuettel <edd at debian.org> wrote:
> 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
> which generally builds fine (and where I just noticed the Mavericks error --
> ick. Anybody with a Mavericks box who can help by poking around ?)
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
[[alternative HTML version deleted]]
More information about the R-package-devel