[R] Error in Calling C++ function from R!!!
gsmatos1
gsmatos1 at ig.com.br
Fri Nov 24 17:59:51 CET 2006
Hello,
I tried to call an external function of R from the following code in C++:
void prodgdot(double *x, double *y, int *n, double *output)
{
int i;
*output=0;
for (i=0;i<*n;i++)
{
*output+=x[i]*y[i];
}
}
I compiled it using from my working directory in linux terminal and I think
it's ok:
giba at giba-desktop:~/mysrc/meus_testes_iniciais$ R CMD SHLIB codigoprova.cc
# The output
g++ -I/usr/share/R/include -I/usr/share/R/include -fpic -g -O2 -c
codigoprova.cc -o codigoprova.o
g++ -shared -o codigoprova.so codigoprova.o -L/usr/lib/R/lib -lR
After, I tried to call R from my working directory an Error occurs:
> x<-c(1,4,6,2)
> y<-c(3,2.4,1,9)
> dyn.load("codigoprova.so")
> is.loaded("codigoprova.so")
[1] FALSE
> product<-.C("prodgdot",myx=x,muy=y,myn=NROW(x),myoutput=as.double(0))
Error in .C("prodgdot", myx = x, muy = y, myn = NROW(x), myoutput =
as.double(0)) :
C symbol name "prodgdot" not in load table
>
Does anyone know what is the problem?
Thank's in advance!
Gilberto.
More information about the R-help
mailing list