Skip to content

Urgent:again question about nmath/standalone

5 messages · xt_wang@cs.concordia.ca, Dirk Eddelbuettel, Brian Ripley +2 more

#
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
#
On Thu, Apr 22, 2004 at 09:37:22AM -0400, xt_wang at cs.concordia.ca wrote:
I'd still recommend the same I sent you last time, e.g. in.

	http://tolstoy.newcastle.edu.au/R/help/04/04/0719.html

Try with a smaller example that does not add your code as e.g. the test file
I sent. I find debugging 'upwards' starting from the simple-most possible,
and verified, test case, and the adding (and verifiying) incrementally, to
be the most bullet-proof method.

Dirk
#
WHY is this urgent?

The error message is '/usr/bin/ld: cannot find -lRmath' so you have not
put libRmath somewhere ld can find it.  That is not an R question, and we
can't help you solve it, especially as you have not told us your OS.  It
does look as if you may not have permission to read the copies in
/usr/lib, but you haven't told us whether your user account is the same as
bcdesai, not the search path ld is using.  Please ask your local OS 
support for help.
On Thu, 22 Apr 2004 xt_wang at cs.concordia.ca wrote:

            

  
    
#
Dirk Eddelbuettel <edd at debian.org> writes:
Well, yes, but in the present case there are a couple of fairly
obvious things to try fixing. The only Rmath related thing is that the
linking command is missing a -L /usr/lib/R/..../standalone

The rest are problems with the general C programming, e.g. the need to
define or at least declare functions before they are used.
#
Permissions?

  Are you logged in as user 'bcdesai'? Because only that username can 
read the libRmath files in /usr/lib.

  If you are logged in as bcdesai and its still not working, then it 
wouldn't surprise me if linux was paranoid enough to not allow you to 
link to libraries not owned by 'root' in /usr/lib.

  So, change the owner to root and the permissions to 755 and try again. 
You may need your friendly local sysadmin to do this. Or 'bcdesai'.

Baz