[Rcpp-devel] Rcpp: Sort Rcpp:::ldFlags() to LDFLAGS and LDADD

Dirk Eddelbuettel edd at debian.org
Thu Apr 26 13:23:27 CEST 2012


We prefer full names and affiliations here, just like on the R list. Please
introduce yourself.

On 26 April 2012 at 12:58, Mr.M at gmx.at wrote:
| Hello.
| I have a question/suggestion concering Rcpp.
| Recently I was trying to get the Gnu Binutils Autotools working inside an R-package.
| (configure.in, Makefile.am,...autoreconf,...)

Ambitious :)

We learned the hard way that you shouldn't bother.  R does all that for you
via 'R CMD ...'.

Moreover, R knows how to do it for multiarch packages that do i386 as well as
x64 (on Windows and Mac; presumably 'soon' on Linux once all distros support

Once you have a Makefile, this breaks. Which is bad.
| In order to get the Compiler-flags in an Rcpp-project right, usually the file "Makevars" is used, where the function Rcpp:::LdFlags() or RcppClassic:::LdFlags() writes the linkerflags and some additional flags into an environment variable.

Not so. It simply runs cat(). I usually assign it to Make variable. See eg
the Makefile for RInside's inst/examples/standard/

| In the case of the Gnu autotools however, this does not work, because the gnu autotools expect the linkerflags (-L) and the additional flags to be specified separately.
| I tried to "fool" the autotools by putting both types of flags into one of those constants, however the gnu autotools has a built-in condition to reject flags in the wrong constants.
| So my only solution was to sort the flags during the configure-step into the two constants. (see below)
| (I separated them depending on whether they start with an "-L" or not.)
| The code is so extremly ugly, because many terms have to be double- or tripple-escaped to be syntactically correct.
| Did I overlook a function or an argument in Rcpp::: or RcppClassic::: which outputs these two types of flags separately?
| If such functions are definately not there, could they be added?

There is no such function.

I am very hesitant to add one. Whenever we made changes to this part, it
often require more changes and fixes. What we have right now works on all
five architectures used by CRAN, and it works well for lots of users. 

Plus, your motivation is, as I argue above, not quite on target as Writing R
Extensions etc do not suggest to use autotools inside a package.  

So while I remained unconvinced that this is a good change, there is one
thing that you could to in the meantime is to just write a local package of
your own which shadows our RcppLdFlags.R file but uses your local variant for
-l as well as -L.

Sorry,  Dirk
| regards, Mr.M
| PS.: I hope that I have not overlooked a solution or a post that deals with this...
| +-------------------+
| | /src/configure.in |
| +-------------------+
| AC_INIT(Rmyproject.cpp)
| PACKAGE=rmyproject
| VERSION=0.1.0
| RCPPCXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"``Rscript -e "cat(paste(\" -I\",RcppClassic:::RcppClassic.system.file(),\"/include\",sep=\"\"))"`
| RCPPLDFLAGS=`Rscript -e "cat(paste(grep(\" -L\",paste(\" \",strsplit(capture.output(Rcpp:::LdFlags()),\" \")@<:@@<:@1@:>@@:>@), value = TRUE, invert=TRUE, ignore.case=TRUE),collapse=\"\"))"``Rscript -e "cat(paste(grep(\" -L\",paste(\" \",strsplit(capture.output(RcppClassic:::LdFlags()),\" \")@<:@@<:@1@:>@@:>@), value = TRUE, invert=TRUE, ignore.case=TRUE),collapse=\"\"))"`
| RCPPLDADD=`Rscript -e "cat(paste(grep(\" -L\",paste(\" \",strsplit(capture.output(Rcpp:::LdFlags()),\" \")@<:@@<:@1@:>@@:>@), value = TRUE, ignore.case=TRUE),collapse=\"\"))"``Rscript -e "cat(paste(grep(\" -L\",paste(\" \",strsplit(capture.output(RcppClassic:::LdFlags()),\" \")@<:@@<:@1@:>@@:>@), value = TRUE,  ignore.case=TRUE),collapse=\"\"))"`
| AC_OUTPUT(Makefile myproject/src/Makefile)
| +------------------+
| | /src/Makefile.am |
| +------------------+
| EXTRA_PROGRAMS = Rmyproject.so
| Rmyproject_so_SOURCES = Rmyproject.cpp coding2.cpp coding3.cpp
| Rmyproject_so_CXXFLAGS = -fPIC @RCPPCXXFLAGS@ -I$(R_INCLUDE_DIR) -I./myproject/src
| Rmyproject_so_LDFLAGS = -shared @RCPPLDFLAGS@ -Wl,-rpath,$(R_PACKAGE_DIR)/libs  
| Rmyproject_so_LDADD = @RCPPLDADD@ $(LIBR) -L./ -lmyproject
| all: Rmyproject.so
| +------------+
| | /configure |
| +------------+
| cd ./src
| ./configure
| cd ..
| -- 
| NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
| Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com

More information about the Rcpp-devel mailing list