[Rcpp-devel] Rcpp on Linux Ubuntu 11.04/Netbeans 7

Dirk Eddelbuettel edd at debian.org
Wed Dec 28 19:48:22 CET 2011


Salut Pascal,

Thanks for posting here.

On 28 December 2011 at 19:20, pasparis at noos.fr wrote:
| Hello 
| 
| I have trouble running Rcpp on a Ubuntu 11.04 machine with Netbeans
| 
| I have done the following things:
| 
| 1-install r-base-dev and r-cran-rcpp from the ubuntu synaptic
| 2-collect the headers Rcpp,Rcppcomon, take also the includes directory Rcpp and
| R_Ext
| 3- link with libRcpp.so and libR.so
| 4- compile the following code with no problem
| #include "Rcpp.h"
| main()
| {
| Rcpp::NumericVector ab(2);
| }
| 5- get a RUN FAILED message from netbeans
| 
| do I miss something? thanks a lot in advance for information

a)   First off, please show complete compile and link instructions. You may
     need to set the rpath etc.

     I would recomment trying to get the build done 'by hand' on a shell
     prompt.


b)   Your example reveals a certain lack of familiarity with what Rcpp is and
     does.  Rcpp is primarily for easuer R and C++ data exchange, mostly in
     the context of main add-on functions for R using the .Call() interface
     described in Writing R Extensions.

     The example as you coded /will/ segfault as there is is no related R
     instance anywhere.  You either use Rcpp to extend _an already running R
     instance_ with your functions or package, or use RInside -- see the next
     point.


c)   If you want to add R to a standalone C++ program, you probably want to
     look at RInside.  It has _dozens_ of examples that build when you do
     'make' in the example directory.  Try to understand how they are built
     before switching to Netbeans.

     For your example, I copied to code to the (SVN source) directory of the
     package examples; the Makefile automatically adapts for building 'foo'
     from 'foo.cpp'.  I also added the RInside header, and made sure R gets
     instantiated: 


-----------------------------------------------------------------------------
edd at max:~/svn/rinside/pkg/inst/examples/standard$ cat pascal.cpp 

#include "RInside.h"

int main(int argc, char *argv[]) {
    RInside R(argc, argv);	// basic R instance

    Rcpp::NumericVector ab(2);

    Rprintf("The end.\n");

    return 0;
}
edd at max:~/svn/rinside/pkg/inst/examples/standard$ make pascal
g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/include -O3 -pipe -g -Wall    pascal.cpp  -L/usr/lib/R/lib -lR  -lblas -llapack -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o pascal
edd at max:~/svn/rinside/pkg/inst/examples/standard$ ./pascal
The end.
edd at max:~/svn/rinside/pkg/inst/examples/standard$ 
-----------------------------------------------------------------------------


Note how the compile / link command has to refer to R, Rcpp and RInside.  All
that is computed for you via the Makefile at compile-time.   How that is
done is something you will have to adapt to Netbeans.   Once you have it
worked out, feel free to contribute your solution back here.  Others have
indicated they may contribute documentation for Eclipse and KDevelop too.


Dirk


-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list