Dear All I'm currently developing a package for R (1.9.0) on Win32, with C++ source code. Having followed the instructions in readme.packages, my code compiles fine with R CMD SHLIB (as well as R CMD check) ... until I start using the internal R functions. (Interesting: Rprintf seems to be the exception.) For instance, the following code compiles fine: #include <R.h> #include <Rdefines.h> ... SEXP whatever (SEXP model) { Rprintf ("Hello, here I am!\n"); return model; } However, the following doesn't compile at all: #include <R.h> #include <Rdefines.h> ... SEXP whatever (SEXP model) { SEXP anotherModel; PROTECT(anotherModel = NEW_NUMERIC(4)); UNPROTECT(1); return anotherModel; } An example of compiler feedback from R CMD SHLIB (I have mingw 3.1.0): ...: undefined reference to 'Rf_allocVector(unsigned,int)' ...: undefined reference to 'Rf_protect(SEXPREC*)' ...: undefined reference to 'Rf_unprotect(int)' Can anybody tell me what the matter is? Did I miss something? My PATH variable is as follows: C:\R\tools;C:\Perl\bin\;C:\mingw\bin;c:\R\rw1090\bin;C:\Program Files\MiKTeX\miktex\bin;...;C:\Program Files\HTML Help Workshop I should mention that I'm a complete R and C++ newbie; any help would be sincerely appreciated. Regards Alet ------------------------------------- Alet Roux Department of Mathematics University of Hull Kingston upon Hull HU6 7RX United Kingdom URL: http://www.hull.ac.uk/php/mapar/ Tel: +44 (1482) 466463 Fax: +44 (1482) 466218
Prof Brian Ripley
2004-Jun-16 15:58 UTC
[R] Compiling C++ package source: linking problem?
On Wed, 16 Jun 2004, Alet Roux wrote:> Dear All > > I'm currently developing a package for R (1.9.0) on Win32, with C++ source code. > Having followed the instructions in readme.packages, my code compiles fine with > R CMD SHLIB (as well as R CMD check) ... until I start using the internal R > functions. > > (Interesting: Rprintf seems to be the exception.) For instance, the following > code compiles fine: > > #include <R.h> > #include <Rdefines.h> > ... > SEXP whatever (SEXP model) > { > Rprintf ("Hello, here I am!\n"); > return model; > } > > However, the following doesn't compile at all: > > #include <R.h> > #include <Rdefines.h> > ... > SEXP whatever (SEXP model) > { > SEXP anotherModel; > PROTECT(anotherModel = NEW_NUMERIC(4)); > UNPROTECT(1); > return anotherModel; > } > > An example of compiler feedback from R CMD SHLIB (I have mingw 3.1.0): > ...: undefined reference to 'Rf_allocVector(unsigned,int)' > ...: undefined reference to 'Rf_protect(SEXPREC*)' > ...: undefined reference to 'Rf_unprotect(int)' > > Can anybody tell me what the matter is? Did I miss something?Are you linking against the R.dll via its import library libR.a? Did the latter get made correctly? That is where those entry points are. More complete compiler output would have helped here. -- 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