I am trying to understand the role and relationship of the macros/variables set in ~/.R/Makevars
and package_directory/src/Makevars
when installing/building own R packages. Suppose these files look like
~/.R/Makevars
CXX = g++
CXXSTD = -std=c++11
CXXFLAGS = -fsanitize=undefined,address -fno-omit-frame-pointer
CXX98 = g++
CXX98STD = -std=c++98
CXX11 = g++
CXX11STD = -std=c++11
CXX14 = g++
CXX14STD = -std=c++14
package_directory/src/Makevars
PKG_CPPFLAGS = -I../inst/include
CXX_STD = CXX11
As I understand it, with CXX
we can select the compiler for C++ when building R packages, with CXXSTD
we chose the standard and with CXXFLAGS
we add compiler flags. With PKG_CPPFLAGS
we add flags for the C++ preprocessor and with CXX_STD
we tell that our packages uses C++11.
I have the following questions:
CXX
and CXX98
, CXX11
and CXX14
?CXX11STD = -std=c++11
if C++11 is already implied? Is it between choosing -std=c++11
and -std=gnu++11
? Should -std=gnu++11
generally be avoided for portability reasons?CXXSTD
and CXXFLAGS
not just be added to CXX
, such that the first three lines reduce to CXX = g++ -std=c++11 -fsanitize=undefined,address -fno-omit-frame-pointer
. What is the advantage in explicity specifying CXXSTD
and CXXFLAGS
?CXX_STD = CXX11
work? How is CXX11
here related to CXX11
in ~/.R/Makevars
?CXXFLAGS
and PKG_CXXFLAGS
(not included in my example)? I am aware of the information contained in Writing R Extensions and R Installation and Administration, but I am not able to extract more information beyond my current level of understanding to answer the above questions.
I am adding a Rcpp
tag because I suppose that answers to these questions will be most relevant to users of Rcpp
, but I am aware that this is probably not directly related to Rcpp
, so the tag might be removed if deemed appropriate.