开发者

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

开发者 https://www.devze.com 2023-02-04 18:51 出处:网络
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 i

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.


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.


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消