[Phylobase-devl] [Fwd: phylobase]

Dirk Eddelbuettel edd at debian.org
Thu Dec 10 16:10:30 CET 2009


On 10 December 2009 at 08:37, Ben Bolker wrote:
|   The C++ interfacing is a fairly regular irritation for us, it would be
| great to improve it/clean it up -- I'm cc'ing/forwarding this question
| to the rest of the dev team, some of whom may have more informed
| opinions (Brian?)

I'd be glad to help -- Rcpp itself is r-forge and CRAN too.  

I hope you find the package easier to use.  If your DESCRIPTION: has a
Depends: Rcpp then all you need may be (and this is more verbose / longer than
it needs to be -- and this is fron configure.in of the RProtoBuf package also
on R-Forge)



AC_DEFUN([AC_PROG_R], [AC_CHECK_PROG(R,R,yes)])
AC_PROG_R

## With thanks to Kurt
: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
    AC_MSG_ERROR([Could not determine R_HOME.])   
fi
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS`

## look for Rscript, but use the one found via R_HOME to allow for multiple installations
AC_DEFUN([AC_PROG_RSCRIPT], [AC_CHECK_PROG(RSCRIPT,Rscript,yes)])
AC_PROG_RSCRIPT
if test x"${RSCRIPT}" == x"yes" ; then
    ## Rcpp compile flag providing header directory containing Rcpp.h
    rcpp_cxxflags=`${R_HOME}/bin/Rscript -e 'Rcpp:::CxxFlags()'`
    ## link flag providing libary as well as path to library, and optionally rpath
    rcpp_ldflags=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'`
else
    echo "
  Your installation does not appear to have Rscript installed.

  Please make sure that you have a working and complete R installation.
"
    exit 1
fi



Ie I ask Rcpp itself about values of -I and -L I need to use (thanks to a
suggestion by Simon).  You then to paste the variab;e rcpp_cxxflags and
rcpp_ldflags into the PKG_CPPFLAGS and PKG_LIBS as I do here (after having
found values for the ProtoBuf lib):


## now use all these
AC_SUBST([PKG_CPPFLAGS],["${PKG_CPPFLAGS} $rcpp_cxxflags $protobuf_cxxflags"])
AC_SUBST([PKG_LIBS],["${PKG_LIBS} $rcpp_ldflags $protobuf_libs"])
AC_OUTPUT(src/Makevars)


That should be it. Other than that, Rcpp.h receives updates required by more
recent g++ versions and some more sanity w.r.t. to namespaces etc.  You may now
need to call Rf_error() instead of error() but that should be it.

Oh, one last thing: I like and prefer dynamic linking, but you can also link
Rcpp statically as you currently do.  There is a 'static=FALSE)' argument to
RcppLdFlags you could tickle.

Dirk

(PS Please forward to to the phylobase-dev list in case I can't post there as
a non-subscriber)

-- 
Three out of two people have difficulties with fractions.


More information about the Phylobase-devl mailing list