[R] question about /nmath/standalone

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Wed Apr 14 19:44:21 CEST 2004


xt_wang at cs.concordia.ca wrote:

> Hello,
> 
> I can't link a c code with Mathlib according to introduction of R 
> manual "Writing R Extensions", page 60.
> 
> It is written :
> "It is possible to build Mathlib, the R set of mathematical functions 
> documented in
> 'Rmath.h’, as a standalone library 'libRmath’ under Unix and Windows. (This 
> includes
> the functions documented in Section 5.7 [Numerical analysis subroutines], page 
> 61 as fromthat header file.)
> 
> The library is not built automatically when R is installed, but can be built 
> in the
> directory 'src/nmath/standalone’ in the R sources: see the file 'README’ 
> there. To use thecode in your own C program include
> 
> #define MATHLIB_STANDALONE
> #include <Rmath.h>
> 
> and link against '-lRmath’. There is an example file 'test.c’."
> 
> Have I to do: gcc -lRmath test.c ? In this case I receive this message: 
> 
> 
>>/usr/bin/ld: cannot find -lRmath 
>>collect2: ld returned 1 exit status "
> 
> 
> what should I do? or I do something before I use "gcc -lRmath test.c" to 
> compile c code test.c?
> 
> I will appreciate if you can help me resolve this problem.
> 
> yours,
> 
> Maggie Wang
> 

Hi Maggie,

(I'm not sure what OS you are using. You never specified. The following 
works in Windows.)

You should use

gcc test.c -o test.exe -L/path/to/Rmath -lRmath

e.g. if Rmath.dll is in C:/R/R-1.9.0/src/nmath/standalone

gcc test.c -o test.exe -LC:/R/R-1.9.0/src/nmath/standalone -lRmath

Then make sure test Rmath.dll is in your path so that test.exe knows 
where the dll is.

--sundar




More information about the R-help mailing list