[Rcpp-devel] calling a homegrown cpp function from my own package when using sourceCpp
Søren Højsgaard
sorenh at math.aau.dk
Mon Dec 30 15:27:40 CET 2013
Thanks for your answers, Romain and Dirk!
I am reluctant to follow Romains suggestion because the package has a lot of c-code in it, so using load_all() takes quite some time because all c and c++ code is being compiled. (Maybe that is just slow on windows? I tried on linux (ubuntu) too but I can't get devtools installed (because RCurl for some reason can't be installed)).
I am following Dirks suggestion (and I believe that I am following section 3.5 in "Rcpp Attributes"): I have:
#include <mypack.h>
//[[Rcpp::depends(mypack)]]
using namespace Rcpp;
//[[Rcpp::export]]
NumericVector aperm2_cpp(NumericVector AA, IntegerVector adim, IntegerVector perm){
NumericVector out( AA.length() );
IntegerVector pp = permuteCellEntries_cpp(perm, adim);
return(out);
}
/*** R
x <- HairEyeColor
pp <- c(2,3,1)
aperm(x, pp)
aperm2_cpp(x, dim(x), pp)
*/
sourceCpp("perm-array14.cpp")
In file included from c:/programs/R/current/library/mypack/include/mypack.h:7:0,
from perm-array14.cpp:1:
c:/programs/R/current/library/mypack/include/mypack_RcppExports.h:7:27: fatal error: RcppArmadillo.h: No such file or directory
compilation terminated.
make: *** [perm-array14.o] Error 1
Warning message:
running command 'make -f "c:/programs/R/current/etc/x64/Makeconf" -f "c:/programs/R/current/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_63425.dll" WIN=64 TCLBIN=64 OBJECTS="perm-array14.o"' had status 2
g++ -m64 -I"c:/programs/R/current/include" -DNDEBUG -I"c:/programs/R/current/library/Rcpp/include" -I"c:/programs/R/current/library/mypack/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c perm-array14.cpp -o perm-array14.o
Error in sourceCpp("perm-array14.cpp") :
Error 1 occurred building shared library.
I am sorry but I am a bit lost here. I've taken the liberty to attach my package and the "new file" in case anyone has a moment to look at it.
Thanks in advance for any additional help.
All the best
Søren
-----Original Message-----
From: Dirk Eddelbuettel [mailto:edd at debian.org]
Sent: 30. december 2013 03:13
To: Søren Højsgaard
Cc: rcpp-devel at r-forge.wu-wien.ac.at
Subject: Re: [Rcpp-devel] calling a homegrown cpp function from my own package when using sourceCpp
Hi Søren,
On 30 December 2013 at 01:59, Søren Højsgaard wrote:
| I have created a function c++ function foo which I export with //[[Rcpp::export]]. I've put the file foo.cpp with the function into the src dir of the package mypack; I've run compileAttributes and I can see the function in mypack_RcppExport.h and the automatically generated interface to the function is available in R (these Rcpp-attributes really make life easier).
|
| Now I want to develop another function bar in the file bar.cpp and bar
| depends on foo. I want to develop bar using sourceCpp("bar.cpp") but I can not figure out how to make my c++ function foo available to bar. In bar.cpp I have //[[Rcpp::depends(mypack)]] but that does not make foo available.
|
| Is it possible to do what I want (I believe it is from the documentation?) or is there another "workaround"??
I think Section 3.5 in the vignette 'Rcpp Attributes' is what you want here.
Happy New Year to you too!
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mypack_1.0.tar.gz
Type: application/x-gzip
Size: 6722 bytes
Desc: mypack_1.0.tar.gz
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131230/1ae034fd/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: perm-array14.cpp
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131230/1ae034fd/attachment.ksh>
More information about the Rcpp-devel
mailing list