[Rd] Specifying C Standard in Package's Makevars File

Prof Brian Ripley r|p|ey @end|ng |rom @t@t@@ox@@c@uk
Tue Sep 29 16:35:54 CEST 2020


On 28/09/2020 12:44, Andreas Kersting wrote:
> Hi,
> 
> what is the correct way to specify a C standard in a package's Makevars file?
> 
> Building a package with e.g. PKG_CFLAGS = -std=gnu11 does work but R CMD check issues a warning:

for some unstated value of 'work' ...

> * checking compilation flags in Makevars ... WARNING
> Non-portable flags in variable 'PKG_CFLAGS':
>    -std=gnu11
> 
> (Same for -std=c11.)
> 
> Thanks! Regards,
> Andreas Kersting

Those flags are not portable, as 'check' correctly says.  Furthermore, 
on some platforms there may be no flag which can be added -- R documents 
that 'CC' specifies a C99 compiler, and that or CC+CFLAGS are likely to 
specify flags which are incompatible with -std=c11 (true on Solaris 
where -xc99 is used).

So, like all such overrides (see 'Writing R Extensions') you need to 
write a configure script (preferably using autoconf) to

- select an appropriate C compiler+flags
- substitute them into src/Makefile.in

For the new features I have used in C11, all known compilers make them 
available in C99 mode and a configure script could be used to test for 
their presence (as R itself does).  That is, it is rare to actually need 
to specify C11 mode.

-- 
Brian D. Ripley,                  ripley using stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford



More information about the R-devel mailing list