Hi, I've created a shared library from including this code (with g++ -I/usr/local/lib/R/include -I/usr/local/include -c Rtest.cpp; g++ -shared -L/usr/local/lib -o Rtest.so Rtest.cpp): void check_data (SEXP data) { int l=length (data); } But when I try to load it in R I get this error message: unable to load shared library ... ... undefined symbol: _Z9Rf_lengthP7SEXPREC How can I solve this problem? Philip
Did you follow the instructions in Writing R Extensions? You need to make sure you include the proper header files, as length is a C and not C++ export from R.bin, and in any case it is remapped in R. On Mon, 1 Sep 2003, Philip Silva wrote:> Hi, > > I've created a shared library from including this code (with g++ > -I/usr/local/lib/R/include -I/usr/local/include -c Rtest.cpp; g++ > -shared -L/usr/local/lib -o Rtest.so Rtest.cpp): > void check_data (SEXP data) { > int l=length (data); > } > > But when I try to load it in R I get this error message: > unable to load shared library ... > ... > undefined symbol: _Z9Rf_lengthP7SEXPREC > > How can I solve this problem?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Philip - Why not compile and load using the unix command line: R CMD SHLIB <files> rather than try to write your own compiler flags ? See help("SHLIB"), help("COMPILE") inside R. You may have a good reason for NOT going the ordinary route, but you need to tell us what it is. And do try the ordinary method for us, first, and please tell us what difficulties you encounter there. - tom blackwell - u michigan medical school - ann arbor - On Mon, 1 Sep 2003, Philip Silva wrote:> I've created a shared library from including this code > (with g++ -I/usr/local/lib/R/include -I/usr/local/include -c Rtest.cpp; > g++ -shared -L/usr/local/lib -o Rtest.so Rtest.cpp): > > void check_data (SEXP data) { > int l=length (data); > } > > But when I try to load it in R I get this error message: > unable to load shared library ... > ... > undefined symbol: _Z9Rf_lengthP7SEXPREC > > How can I solve this problem? > > Philip