Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference error while linking to R and RInside libraries from C++ code using g++ compiler in UNIX

Tags:

c++

r

g++

rcpp

rinside

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.

like image 209
Manoj Avatar asked Nov 05 '25 22:11

Manoj


2 Answers

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.

like image 162
Dirk Eddelbuettel Avatar answered Nov 08 '25 14:11

Dirk Eddelbuettel


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

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

like image 33
EmeryBerger Avatar answered Nov 08 '25 12:11

EmeryBerger