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

Mr.M at gmx.at Mr.M at gmx.at
Thu Apr 26 12:58:34 CEST 2012


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,...)

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.

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?


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

AM_INIT_AUTOMAKE($PACKAGE, $VERSION)

AC_PROG_CXX

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_SUBST(RCPPCXXFLAGS)
AC_SUBST(RCPPLDFLAGS)
AC_SUBST(RCPPLDADD)

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


More information about the Rcpp-devel mailing list