For more information, see the “Writing R-Extensions” manual, which you can easily compile and link to Rmath.h and the R Math stand-alone library, but not Rh (What you can use through Rcpp / RInside, but that's another story.)
There are a number of examples that you can use to use libRmath, one of which is in the manual itself. Here is one I am sending to the Debian r-mathlib containing this standalone math library:
#define MATHLIB_STANDALONE 1 #include <Rmath.h> #include <stdio.h> typedef enum { BUGGY_KINDERMAN_RAMAGE, AHRENS_DIETER, BOX_MULLER, USER_NORM, INVERSION, KINDERMAN_RAMAGE } N01type; int main(int argc, char** argv) { /* something to force the library to be included */ qnorm(0.7, 0.0, 1.0, 0, 0); printf("*** loaded '%s'\n", argv[0]); set_seed(123, 456); N01_kind = AHRENS_DIETER; printf("one normal %f\n", norm_rand()); set_seed(123, 456); N01_kind = BOX_MULLER; printf("normal via BM %f\n", norm_rand()); return 0; }
and on Linux you just build like this (as I put the library and the header in standard places in the package; add -I and -L as needed on OS X)
/tmp $ cp -vax /usr/share/doc/r-mathlib/examples/test.c mathlibtest.c `/usr/share/doc/r-mathlib/examples/test.c' -> `mathlibtest.c' /tmp $ gcc -o mathlibtest mathlibtest.c -lRmath -lm /tmp $ ./mathlibtest *** loaded '/tmp/mathlibtest' one normal 1.119638 normal via BM -1.734578 /tmp $
source share