[R] Looking for protect()

Richards, Tom richards at pci.upmc.edu
Tue Jun 27 00:37:35 CEST 2000


Hello:

This is a simple, I hope, question about the first example in section 3.6.4
of the manual, "Writing R extensions."

I'm using R 1.1.0, and below I list some easy code that I got from section
3.6.4.  When I try to compile the file out.c under NT 4, using VC++ 6.0, I
get the following error messages:

Compiling...
out.c
Linking...
out.obj : error LNK2001: unresolved external symbol _Rf_unprotect
out.obj : error LNK2001: unresolved external symbol _Rf_protect
out.obj : error LNK2001: unresolved external symbol _Rf_allocMatrix
out.obj : error LNK2001: unresolved external symbol _Rf_length

I see, for example, that PROTECT(s) is #defined as protect(s) in R.h,
#ifndef R_NO_REMAP. If I do nothing, I get the errors above, and if I
#idefine R_NO_REMAP, I get the following errors, instead:

Compiling...
out.c
Linking...
out.obj : error LNK2001: unresolved external symbol _unprotect
out.obj : error LNK2001: unresolved external symbol _protect
out.obj : error LNK2001: unresolved external symbol _allocMatrix
out.obj : error LNK2001: unresolved external symbol _length

I cannot seem to find these 4 functions anywhere.  Hopefully, I am just
missing them.  Can anyone help?  Here is the file out.c:

#include <R.h>

#include <Rinternals.h>

SEXP out(SEXP x, SEXP y)

{

int i, j, nx, ny;

double tmp;

SEXP ans;

nx = length(x); ny = length(y);

PROTECT(ans = allocMatrix(REALSXP, nx, ny));

for(i = 0; i < nx; i++) {

tmp = REAL(x)[i];

for(j = 0; j < ny; j++)

REAL(ans)[i + nx*j] = tmp * REAL(y)[j];

}

UNPROTECT(1);

return(ans);

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000626/1d78cb97/attachment.html


More information about the R-help mailing list