[Rd] CXX_STD and configure.ac in packages

Romain Francois romain at r-enthusiasts.com
Mon Mar 31 08:22:35 CEST 2014


My advice would be to use SystemRequirements: C++11

As <unordered_map> is definitely a part of C++11, assuming this version of the standard gives it to you. Your package may not compile on platforms where a C++11 compiler is not available, but perhaps if this becomes a pattern, then such compilers will start to be available, as in the current version of OSX and recent enough versions of various linux distributions. 

The subset of feature that the version of gcc gives you with Rtools might be enough. 

Alternatively, if you use Rcpp, you can use the RCPP_UNORDERED_MAP macro which will expand to either unordered_map or tr1::unordered_map, all the condition compiling is done in Rcpp. 


Le 30 mars 2014 à 21:50, Martin Morgan <mtmorgan at fhcrc.org> a écrit :

> In C++ code for use in a R-3.1.0 package, my specific problem is that I would like to use <unordered_map> if it is available, or <tr1/unordered_map> if not, or <map> if all else fails.
> I (think I) can accomplish this with configure.ac as
> CXX=`"${R_HOME}/bin/R" CMD config CXX`
> CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS`
> AC_CONFIG_HEADERS([src/config.h])
> AC_LANG(C++)
> AC_CHECK_HEADERS([unordered_map tr1/unordered_map])
> Use of configure.ac does not seem to be entirely consistent with section 1.2.4 of Writing R Extensions, where one is advised that to use C++(11? see below) code one should
>    CXX_STD = CXX11
> in Makevars(.win). My code does not require a compiler that supports the full C++11 feature set. In addition, I do not understand the logic of setting a variable that influences compiler flags in Makevars -- configure.ac will see a compiler with inaccurate flags.
> Is use of configure.ac orthogonal to setting CXX_STD=CXX11?
> Some minor typos:
> /R-3-1-branch$ svn diff
> Index: doc/manual/R-exts.texi
> ===================================================================
> --- doc/manual/R-exts.texi	(revision 65339)
> +++ doc/manual/R-exts.texi	(working copy)
> @@ -2250,7 +2250,7 @@
> @subsection Using C++11 code
> @R{} can be built without a C++ compiler although one is available
> -(but not necessarily installed) or all known @R{} platforms.
> +(but not necessarily installed) on all known @R{} platforms.
> For full portability across platforms, all
> that can be assumed is approximate support for the C++98 standard (the
> widely used @command{g++} deviates considerably from the standard).
> @@ -2272,7 +2272,7 @@
> support a flag @option{-std=c++0x}, but the latter only provides partial
> support for the C++11 standard.
> -In order to use C++ code in a package, the package's @file{Makevars}
> +In order to use C++11 code in a package, the package's @file{Makevars}
> file (or @file{Makevars.win} on Windows) should include the line
> @example
> @@ -2329,7 +2329,7 @@
> anything other than the GNU version of C++98 and GNU extensions (which
> include TR1).  The default compiler on Windows is GCC 4.6.x and supports
> the @option{-std=c++0x} flag and some C++11 features (see
> - at uref{http://gcc.gnu.org/gcc-4.6/cxx0x_status.html}.  On these
> + at uref{http://gcc.gnu.org/gcc-4.6/cxx0x_status.html}).  On these
> platforms, it is necessary to select a different compiler for C++11, as
> described above, @emph{via} personal @file{Makevars} files.  For
> example, on OS X 10.7 or later one could select @command{clang++}.
> -- 
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
> Location: Arnold Building M1 B861
> Phone: (206) 667-2793
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list