[R] How to resolve include Rcpp.h problems?
Amine Jallouli
jallouli.med.amine at gmail.com
Sun Dec 13 21:06:19 CET 2009
Thank you Romain and Dirk.
The problem is solved. It works well.
I created the file src/Makevars, then I added these lines:
PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'`
PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'`
Good night.
Dirk Eddelbuettel wrote:
>
>
> On 13 December 2009 at 19:37, Romain Francois wrote:
> | Hi,
> |
> | The file lives in the lib directory of the installed package Rcpp.
> |
> | Rscript -e "cat(system.file( 'lib', 'Rcpp.h', package = 'Rcpp' ))"
>
> Yes, and we typically use similar tricks to build with Rcpp -- suppose
> your
> file is called myfile.cpp then you can use (if you have littler)
>
> PKG_CPPFLAGS=`r -e'Rcpp:::CxxFlags()'` \
> PKG_LIBS=`r -e'Rcpp:::LdFlags()'` \
> R CMD SHLIB myfile.cpp
>
> and R CMD SHLIB will know where to find Rcpp.h and the other headers as
> well
> as libRcpp.so (or .a).
>
> If you don't have littler, you can use the same with Rscript as well
>
> PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` \
> PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'` \
> R CMD SHLIB myfile.cpp
>
> and that should work portably. Likewise, you can set
> PKG_CPPFLAGS and PKG_LIBS in src/Makevars if you build a package.
>
> I am right working on integrating the cfunction() from the rather useful
> inline package into Rcpp; this may also appear appear in the inline
> package
> itself if its maintainer accepts my patch and makes a new release. With
> version in SVN you can now say
>
> -----------------------------------------------------------------------------
> suppressMessages(library(Rcpp))
>
> foo <- '
> SEXP rl = R_NilValue; // Use this when there is nothing to be
> returned.
> char* exceptionMesg = NULL; // msg var in case of error
>
> try {
> RcppVector<int> vec(v); // vec parameter viewed as vector of ints.
> int n = vec.size(), i = 0;
> if (n != 10000) throw std::length_error("Wrong vector size");
> for (int a = 0; a < 9; a++)
> for (int b = 0; b < 9; b++)
> for (int c = 0; c < 9; c++)
> for (int d = 0; d < 9; d++)
> vec(i++) = a*b - c*d;
>
> RcppResultSet rs; // Build result set to be returned as a
> list to R.
> rs.add("vec", vec); // vec as named element with name "vec"
> rl = rs.getReturnList(); // Get the list to be returned to R.
> } catch(std::exception& ex) {
> exceptionMesg = copyMessageToR(ex.what());
> } catch(...) {
> exceptionMesg = copyMessageToR("unknown reason");
> }
>
> if (exceptionMesg != NULL) Rf_error(exceptionMesg);
>
> return rl;
> '
>
> funx <- cfunction(signature(v="numeric"), foo, Rcpp=TRUE)
>
> dd.inline.rcpp <- function() {
> x <- integer(10000)
> res <- funx(v=x)[[1]]
> tabulate(res)
> }
>
> print(mean(replicate(100,system.time(dd.inline.rcpp())["elapsed"]),trim=0.05))
> -----------------------------------------------------------------------------
>
> which means everything works from within R which is rather convenient. I
> am
> currently extending this for arguments for additional header files and
> libraries.
>
> | The maintainer of Rcpp (cc'ed, just in case) will tell you more tricks.
> | Note that Rcpp has its own mailing list.
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> | where questions like this might be more appropriate.
>
> Hehe. So far that mailing has only Romain and myself rambling along.
>
> Dirk
>
> | Romain
> |
> | On 12/13/2009 09:56 AM, Amine Jallouli wrote:
> | >
> | > Hi,
> | > I am Linux Ubuntu 9.04 user. I'm using R-2.6.
> | >
> | > Actually, I am developing R package for reading/writing 3D images. I
> needed
> | > to use the R package Rcpp in order to make profit of available C/C++
> codes.
> | > My problem is that my C code is not able to include the Rcpp.h
> | >
> | > In fact, when I run this command R CMD build rply, I got the following
> error
> | > message in the file /home/amine/R/r-eclipse/rply.Rcheck/00install.out:
> | > * Installing *source* package 'rply' ...
> | > ** libs
> | > gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c
> Call_interface.c
> | > -o Call_interface.o
> | > gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c
> C_interface.c -o
> | > C_interface.o
> | > gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c fifrt.c -o
> | > fifrt.o
> | > g++ -I/usr/share/R/include -fpic -g -O2 -c RCPP_test.cpp -o
> | > RCPP_test.o
> | > RCPP_test.cpp:1:18: erreur: Rcpp.h : No such file or directory
> | > RCPP_test.cpp: In function ‘SEXPREC* readRIntVec(SEXPREC*)’:
> | > RCPP_test.cpp:14: erreur: ‘RcppVector’ was not declared in this scope
> | > RCPP_test.cpp:14: erreur: expected primary-expression before ‘int’
> | > RCPP_test.cpp:14: erreur: expected `;' before ‘int’
> | > make: *** [RCPP_test.o] Erreur 1
> | > ERROR: compilation failed for package 'rply'
> | > ** Removing '/home/amine/R/r-eclipse/rply.Rcheck/rply'
> | >
> | > It is evident that I will this error since the file Rcpp.h is not in
> this
> | > directory /usr/share/R/include .
> | >
> | > I tried to solve this include problem by copying the Rcpp.h to
> | > /usr/share/R/include. But, it was not successful and I the following
> error
> | > message.
> | >
> | > Error in dyn.load(file, DLLpath = DLLpath, ...) :
> | > Unable to load shared library
> | > '/home/amine/R/r-eclipse/rply.Rcheck/rply/libs/rply.so':
> | > /home/amine/R/r-eclipse/rply.Rcheck/rply/libs/rply.so: undefined
> symbol:
> | > _ZN10RcppVectorIiEC1EP7SEXPREC
> | > Error in library(rply) : .First.lib has failed for 'rply'
> | > Execution stopped
> | >
> | > It looks like this package has a loading problem: see the messages for
> | > details.
> | >
> | >
> | > Resulting this last error seems to be also logical. In fact, I think
> the
> | > file libRcpp.so is need for the compilation of my code.
> | >
> | > Please notice that the package Rcpp is installed in the following
> directory:
> | > /usr/lib/R/site-library/Rcpp
> | >
> | > Thank you for giving an idea for solving this problem.
> |
> |
> | --
> | Romain Francois
> | Professional R Enthusiast
> | +33(0) 6 28 91 30 30
> | http://romainfrancois.blog.free.fr
> | |- http://tr.im/HlX9 : new package : bibtex
> | |- http://tr.im/Gq7i : ohloh
> | `- http://tr.im/FtUu : new package : highlight
> |
>
> --
> Three out of two people have difficulties with fractions.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
View this message in context: http://n4.nabble.com/How-to-resolve-include-Rcpp-h-problems-tp962875p963105.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list