[Rd] CXX_STD and configure.ac in packages

Dirk Eddelbuettel edd at debian.org
Mon Mar 31 01:33:57 CEST 2014


Hi Martin,

On 30 March 2014 at 12:50, Martin Morgan wrote:
| 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.

This non-standardization over the last decade caused a lot of headaches.  

We do have a set of tests in Rcpp (see includes/Rcpp/platform/compiler.h) to
find unordered maps and sets (based on the compiler version). Not too
elegant, but it works.

One possible alternative is to simply use Boost, which is now easy thanks to
the BH package.  Then Boost abstracts this for you and you use Boost for
unordered_map and/or unordered_set.
 
| I (think I) can accomplish this with configure.ac as
| 
| AC_INIT("DESCRIPTION")
| 
| 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])
| AC_OUTPUT
| 
| 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.

There were some earlier discussions. Basically, R 'learns' what it has
available when it is built, and the CXX_STD = CXX11 setting then selects 
C++11 (or, on older compilers, C++0x) if available.

But you should be able to get with that. The tr1/ directory is by now pretty
old.  Looking at my current server, which has been around a few years and
upgraded, I see

edd at max:~$ ls -l /usr/include/c++/4.?/unordered_map
-rw-r--r-- 1 root root 2448 Jan 30  2013 /usr/include/c++/4.4/unordered_map
-rw-r--r-- 1 root root 1821 Jul  2  2012 /usr/include/c++/4.5/unordered_map
-rw-r--r-- 1 root root 1852 Jun 19  2013 /usr/include/c++/4.6/unordered_map
-rw-r--r-- 1 root root 1889 Sep 23  2013 /usr/include/c++/4.7/unordered_map
-rw-r--r-- 1 root root 1857 Nov 15 09:22 /usr/include/c++/4.8/unordered_map
edd at max:~$ 

Are you really going to get a compiler older than 4.4 (if in g++ world) ?

I'd try to avoid the configure dance unless you really feel you must have it.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



More information about the R-devel mailing list