簡體   English   中英

本機C程序中的R.h和Rmath.h

[英]R.h and Rmath.h in native C program

“Rh”和“Rmath.h”是R.app和C之間接口的頭文件。但是,它們似乎只能通過R命令'R CMD SHLIB something.c'讀取。

我希望編譯我的本機C程序,使用gcc包含它們。 我正在使用Snow Leopard,我無法找到那些頭文件!

有幫助嗎?

請參閱'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;
}

在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 $ 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM