[R] Urgent:again question about nmath/standalone

xt_wang@cs.concordia.ca xt_wang at cs.concordia.ca
Thu Apr 22 15:37:22 CEST 2004


Hello, all,

I have the same question as the last mail I sent. I have installed libRmath in 
my system. But I still can not link Rmath through -lRmath. The whole process 
is as follow.Is there anybody who is so kind to help me find out the problem? 
I will appreciate very much.

[credsim at confsys ~]$ cd /usr/lib
[credsim at confsys lib]$ ls -l libR*
-rw-------    1 bcdesai  bcdesai    237828 Apr 15 18:10 libRmath.a
lrwxrwxrwx    1 root     root           17 Apr 15 18:12 libRmath.so -> 
libRmath.so.1.0.0
lrwxrwxrwx    1 root     root           17 Apr 15 18:12 libRmath.so.1 -> 
libRmath.so.1.0.0
-rw-------    1 bcdesai  bcdesai    114084 Apr 15 18:10 libRmath.so.1.0.0
[credsim at confsys lib]$ locate test1.c
/b2/home/credsim/src/test1.c
/b2/downloads/a-mp-ms-my-o-p-u/mysql-3.23.55/heap/hp_test1.c
/b2/downloads/a-mp-ms-my-o-p-u/mysql-3.23.55/myisam/ft_test1.c
/b2/downloads/a-mp-ms-my-o-p-u/mysql-3.23.55/myisam/mi_test1.c
/b2/home-apr-18-04-1145Am/credsim/src/test1.c
[credsim at confsys lib]$ cd  /b2/home/credsim/src
[credsim at confsys ~/src]$ gcc -Wall -o test1 test1.c -lRmath -lm
test1.c:12: warning: return type defaults to `int'
test1.c: In function `main':
test1.c:21: warning: implicit declaration of function `Allocate_Memory_2D'
test1.c:21: warning: assignment makes pointer from integer without a cast
test1.c:22: warning: assignment makes pointer from integer without a cast
test1.c:37: warning: too many arguments for format
test1.c:44: warning: implicit declaration of function `solve'
test1.c:44: warning: assignment makes pointer from integer without a cast
test1.c:54: warning: control reaches end of non-void function
test1.c: At top level:
test1.c:58: warning: type mismatch with previous implicit declaration
test1.c:21: warning: previous implicit declaration of `Allocate_Memory_2D'
test1.c:58: warning: `Allocate_Memory_2D' was previously implicitly declared 
to return `int'
/usr/bin/ld: cannot find -lRmath
collect2: ld returned 1 exit status
[credsim at confsys ~/src]$ gcc test1.c -o test1 -lRmath
test1.c: In function `main':
test1.c:21: warning: assignment makes pointer from integer without a cast
test1.c:22: warning: assignment makes pointer from integer without a cast
test1.c:44: warning: assignment makes pointer from integer without a cast
test1.c: At top level:
test1.c:58: warning: type mismatch with previous implicit declaration
test1.c:21: warning: previous implicit declaration of `Allocate_Memory_2D'
test1.c:58: warning: `Allocate_Memory_2D' was previously implicitly declared 
to return `int'
/usr/bin/ld: cannot find -lRmath
collect2: ld returned 1 exit status

"test1.c"
#define MATHLIB_STANDALONE
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include </usr/local/lib/R/include/Rmath.h>

 main()
{

  double **x, **y, **x1, **y1, valin;
  int i,j,I,J;
  

  I=3;
  J=3;

  x=Allocate_Memory_2D( I, J, x1);
  y=Allocate_Memory_2D( I, J, y1);


  FILE *in_file; 


    /* input x value from file data_2Dx.txt */ 
    in_file=fopen("data_2Dx.txt","r");
        if (in_file==NULL)
        {/*Test for error*/
                fprintf(stderr,"Error:Unable to input file 
from 'data_2Dx.txt'\n");
                exit(8);
        }
        for( i=0;i<I; i++)
          for (j=0;j<J;j++)
          { fscanf(in_file, "%lf\n", &valin, stdin);/* read a single double 
value in */
               x[i][j]=valin;
                   valin=0.0;
          }
        fclose(in_file);


   y=solve(x);

   for (i=0;i<I;i++)
     for (j=0;j<J;j++)
     {
       printf ("y[%d][%d]=%lf\n", i, j, y[i][j]);
     }

}


double **Allocate_Memory_2D( int I, int J, double **W)
{ 
        int i;

        W=(double **)malloc(I*sizeof (double *));
    if(!W)
      printf("It is out of memory. Allocation failed.");
        for (i=0;i<I;i++)
        {
        W[i]=(double *)malloc(J*sizeof(double));
        if(!W[i])
          printf("It is out of memory. Allocation failed.");
        }
        return (W);
}

Thanks a lot!

Maggie Wang




More information about the R-help mailing list