本机C程序中的Rh和Rmath.h

Wat*_*ter 6 c macos r

"RH"和"Rmath.h"的头文件和R.app C.但是之间的接口,它们似乎是可读只有通过R指令"R CMD SHLIB something.c"

我希望编译我的本机C程序,使用gcc包含它们.我正在使用Snow Leopard,我无法找到那些头文件!

有帮助吗?

Dir*_*tel 6

请参阅'Writing R Extensions'手册,了解详细信息,您可以轻松编译和链接Rmath.h和独立的R Math库 - 但不是Rh(您可以通过Rcpp/RInside使用,但这是一个不同的故事.)

有许多例子可供使用libRmath,一个在手册本身.这是我在Debian包中发布的r-mathlib包含这个独立数学库的内容:

/* copyright header omitted here for brevity */

#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;
}
Run Code Online (Sandbox Code Playgroud)

在Linux上你只需像这样构建(因为我将库和标题放在包中的标准位置;在OS X上根据需要添加-I和-L)

/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 $ 
Run Code Online (Sandbox Code Playgroud)