3

I want to embed R into a C++ program. So I installed R, Rcpp and RInside also. But I get a lot of "undefined reference to" errors while compiling with g++ in UNIX. The command I give for compiling is

g++ -I/path/to/R/include -I/path/to/Rcpp/include -I/path/to/RInside/include -L/path/to/R/libs -L/path/to/Rcpp/libs -L/path/to/RInside/libs test.cpp -lRlapack -lRcpp -lRblas -lRInside"

test.cpp:

#include <RInside.h>                   
int main(int argc, char *argv[]) {
    RInside R(argc, argv);              // create an embedded R instance
    R["txt"] = "Hello, world!\n";   // assign a char* (string) to 'txt'
    R.parseEvalQ("cat(txt)");           // eval the init string, ignoring any returns
    exit(0);
}

Errors:

Undefined reference to R_ClassSymbol
Undefined reference to R_NilValue

I get similar 110 undefined errors to R variables.I have installed R and other packages to my own location rather than default location. I am stuck with this error for 2 days now.I seem to doing everything right like linking etc. Thanks in Advance.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
Manoj
  • 31
  • 1
  • 2

3 Answers3

2

RInside comes with over ten examples in the examples/standard/ directory (and some more for MPI which you can ignore for now). Try building these, and try adapting from their Makefile.

Your link error message points to missing symbols from R -- and the command you show lacks the -lR part. Try adding that, using the (working) examples as a guide.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • The code above is from that directory. It is a simple 'hello world' program.The lib dir of R contains libRlapack.so and libRblas.so. That is why I gave -lRlapack and -lRblas. There is no libR file in the tree. – Manoj Jan 13 '11 at 16:40
  • Where did you get R from? R itself needs to be built with the --enable-R-shlib option. – Dirk Eddelbuettel Jan 13 '11 at 16:46
  • I got it from CRAN website. I did not buid it with --enable-R-shlib option. I did a simple ./configure and then make, make install. Will try with this option also – Manoj Jan 13 '11 at 16:53
  • In case you are on Ubuntu or Debian, try the prebuilt R packages available from CRAN. – Dirk Eddelbuettel Jan 13 '11 at 17:10
  • Prebuilt R packages?Did not see that in their website.Will install everything afresh again.I am on RHEL. – Manoj Jan 13 '11 at 17:55
  • Istalled everything again.Now getting warning that libgfortran.so.1 required by libR.so not available.Then getting some more undefined errors.I think I have to install libgfortran.so now. – Manoj Jan 14 '11 at 18:39
  • You may want to consult with some R on RH/FC users. Isn't there a r-sig list? It all *just works* on Ubuntu and Debian... – Dirk Eddelbuettel Jan 15 '11 at 14:57
1

(Updated once code was entered properly so I could read it!)

See http://dirk.eddelbuettel.com/code/rinside.html for some useful examples.

EmeryBerger
  • 3,897
  • 18
  • 29
1

Finally got it....Installed everything afresh with -enable-R-shlib in another system.Got the example working fine. I will be able to proceed with some implementations now.Thanks

Manoj
  • 11
  • 1