For the development version of R-devel which will become 4.3.0, there is a new warning in R CMD check
that comes up for some packages:
* checking C++ specification ... NOTE
Specified C++11: please drop specification unless essential
(In earlier versions of R-devel, it said please update to current default of C++17
.)
Link to the code that generates the NOTE.
CRAN is now asking to fix and resubmit packages which raise this NOTE.
This happens when the package's DESCRIPTION file has the following:
SystemRequirements: C++11
Packages that use C++11 generally would also have the following in the src/Makevars
and src/Makevars.win
files (and src/Makevars.ucrt
, if present):
CXX_STD=CXX11
This tells R to use the C++11 standard when compiling the code.
To understand the NOTE, a bit of history will be helpful:
- In R 3.5 and below, on systems with an old compiler, it would default to using the C++98 standard. If a package needed a C++11 compiler, the
DESCRIPTION
file was supposed to haveSystemRequirements: C++11
, and thesrc/Makevars
,src/Makevars.win
, andsrc/Makevars.ucrt
files needed to haveCXX_STD=CXX11
. However, systems with newer compilers appear to default to C++11, even without settingCXX_STD
. - In R 3.6.2, it defaulted to compiling packages with the C++11 (if the compiler supported C++11 -- and in practice, essentially all systems by that time had a C++11 compiler).
- In R 4.0, it required a C++11 compiler, so
SystemRequirements: C++11
was no longer necessary. - In (the forthcoming) R 4.3, it raises a NOTE if
SystemRequirements: C++11
is present, which will block a package submission to CRAN.
- Edit the DESCRIPTION file and remove
SystemRequirements: C++11
. - Edit
src/Makevars
,src/Makevars.win
, andsrc/Makevars.ucrt
and removeCXX_STD=CXX11
.
After making these changes, the package should install without trouble on R 3.6 and above. However, on R 3.5 and below, there may be systems where it won't build (these are systems with very old compilers on them). Note that in my testing on GitHub Actions, with R 3.5 on Ubuntu 20.04 and 22.04, packages using C++11 build just fine. But on systems with older compilers, it could potentially be a problem.
If you want to be confident that your package to still be installable on R 3.5 and below with older compilers, then you need to use a configure
script at the top level of the package, and have it add CXX_STD=CXX11
for R 3.5 and below.
I think something like this would work if you don't already have
src/Makevars
/src/Makevars.win
, orconfigure.R
could be modified to write the entire contents if you do... Adapted from here.If you require building on R <= 3.5.x, you must specify
CXX_STD=CXX11
insrc/Makevars
on those systems. One way to do this is to create the following filesthat check the R version and if it < 3.6.2, sets that flag in
Makevars
. This assumes youdon't already have
src/Makevars
and/orsrc/Makevars.win
already.configure
:configure.win
:cleanup
:cleanup.win
:tools/configure.R
: