R.H和Rmath.h在本地C程序 [英] R.h and Rmath.h in native C program

查看:368
本文介绍了R.H和Rmath.h在本地C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

"R.h" and "Rmath.h" are header files for an interface between R.app and C. But, they seems to be readable only through a R command 'R CMD SHLIB something.c'

我希望编译我的原生的C程序,包括他们使用gcc。我使用雪豹的地方,我无法找到这些头文件!

I wish to compile my native C program to include them using gcc. I'm using Snow Leopard where I'm not able to locate those header files!

任何帮助吗?

推荐答案

请参阅有关细节写作R附加手册,你可以很容易地编译和反对Rmath.h和独立ř数学库的链接 - 但不是相对湿度(您可以通过RCPP / RInside使用但是这是一个不同的故事。)

Please see the 'Writing R Extensions' manual about details, you can easily compile and link against Rmath.h and the standalone R Math library -- but not R.h. (Which you can use via Rcpp / RInside but that is a different story.)

有一些例子左右浮动使用libRmath的,一种是手动本身英寸下面是在Debian软件包 R-mathlib 含有这种独立的数学库中的一个我的船:

There are a number of examples floating around for use of libRmath, one is in the manual itself. Here is one I ship in the Debian package r-mathlib containing this standalone math library:

/* 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;
}

和Linux上您只需建立这样的(因为我放在包中的标准位置的库和头;加上-I和-L根据需要OS X)

and on Linux you simply build like this (as I place the library and header in standard locations 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 $ 

这篇关于R.H和Rmath.h在本地C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆