[R] Compiling C++ package source: linking problem?

Alet Roux A.Roux at hull.ac.uk
Wed Jun 16 17:23:14 CEST 2004

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

(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));
        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:

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.



Alet Roux
Department of Mathematics
University of Hull
Kingston upon Hull
United Kingdom
URL: http://www.hull.ac.uk/php/mapar/
Tel: +44 (1482) 466463
Fax: +44 (1482) 466218

More information about the R-help mailing list