[R] Rmath: R libraries from C on Mac OS X

Murali Haran mharan at stat.psu.edu
Mon Dec 18 05:19:21 CET 2006


Dear R-experts,

I have been having trouble using R's standalone random number generators 
from C on my Mac OS X 10.4.8 system.

I try to compile my C program in the following way:
gcc -Wall -o helloMac helloMac.c -lm -lRmath
I get the following error:
/usr/bin/ld: can't locate file for: -lRmath

I am unable to locate Rmath on my machine. The problem appears to be 
that no libRmath.a was built on my Mac OS X installation. 

Any pointers (perhaps to a step by step guide for a _beginner_ on how to 
install this and then how to compile the C code) would be most 
appreciated.For completeness, here is my C code (adapted from code that 
works fine on Linux):

#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#define MATHLIB_STANDALONE 1
#include 
"/Library/Frameworks/R.framework/Versions/2.3/Resources/include/i386/Rmath.h"

int main(int argc, char *argv[]) {

  printf("hello world\n");
  printf("%lf\n",rnorm(5,2));
  return(0);
}

Many thanks in advance.

Murali



More information about the R-help mailing list