How to deal with the
SystemRequirements: C++11 NOTE when running
R CMD check
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:
Packages that use C++11 generally would also have the following in the
src/Makevars.win files (and
src/Makevars.ucrt, if present):
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
DESCRIPTIONfile was supposed to have
SystemRequirements: C++11, and the
src/Makevars.ucrtfiles needed to have
CXX_STD=CXX11. However, systems with newer compilers appear to default to C++11, even without setting
- 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++11was no longer necessary.
- In (the forthcoming) R 4.3, it raises a NOTE if
SystemRequirements: C++11is present, which will block a package submission to CRAN.
How to fix it
- Edit the DESCRIPTION file and remove
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
configure.Rcould 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
src/Makevarson those systems. One way to do this is to create the following files
that check the R version and if it < 3.6.2, sets that flag in
Makevars. This assumes you
don't already have