我试图使用Emscripten将一些用C语言编写的R函数编译成JavaScript。我的第一个任务是移植一个名为pf
的函数。
可以找到来源here。所以,我进入src目录并尝试运行:
(trunk)⚡ % emcc -s EXPORTED_FUNCTIONS="['_Rf_pf']" nmath/pf.c
warning: unresolved symbol: Rf_pbeta
warning: unresolved symbol: Rf_pchisq
warning: unresolved symbol: R_NaN
warning: unresolved symbol: R_NegInf
warning: unresolved symbol: R_PosInf
我在输出JavaScript中得到一个函数_Rf_pf
。我实际上可以调用此函数并返回结果。但是,由于R_PosInf
和公司未得到解决,它会在R_P_bounds_01(x, 0., ML_POSINF);
上短路。 ML_POSINF
以某种方式设置为0,给出了奇怪的结果。因此,算法的核心不会被执行。
有谁知道如何解决这些符号并将此功能移植?
我可以尝试编译更多源代码,这似乎让我在某处:
$ emcc -s EXPORTED_FUNCTIONS="['_Rf_pf']" nmath/pf.c nmath/pbeta.c nmath/pchisq.c
warning: unresolved symbol: R_finite
warning: unresolved symbol: Rf_pgamma
warning: unresolved symbol: Rf_warning
warning: unresolved symbol: bratio
warning: unresolved symbol: gettext
warning: unresolved symbol: R_NaN
warning: unresolved symbol: R_NegInf
warning: unresolved symbol: R_PosInf
但是,这似乎让我陷入了一个巨大的兔子洞。然后,我遇到了一些障碍:
$ emcc -s EXPORTED_FUNCTIONS="['_Rf_pf']" nmath/pf.c nmath/pbeta.c nmath/pchisq.c main/arithmetic.c
In file included from main/arithmetic.c:35:
include/Defn.h:201:3: error: SIZE_MAX is required for C99
# error SIZE_MAX is required for C99
^
include/Defn.h:639:9: error: unknown type name 'R_size_t'
extern0 R_size_t R_NSize INI_as(R_NSIZE);/* Size of cons cell heap */
^
include/Defn.h:640:9: error: unknown type name 'R_size_t'
extern0 R_size_t R_VSize INI_as(R_VSIZE);/* Size of the vector heap */
^
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
请注意,我有CPATH设置。我不知道这是否是将编译器指向我需要的不同标头的方法:
(trunk)⚡ % echo $CPATH
gnuwin32/fixed/h/:/usr/local/Cellar/r/3.1.2_1/include/:/usr/local/Cellar/r/3.1.2_1/R.framework/Versions/3.1/Resources/include/:nmath/:include/:main/:include/R_ext
答案 0 :(得分:0)
如果您想使用gnuwin32/fixed/h/config.h
,则需要-DHAVE_CONFIG_H
。
https://github.com/wch/r-source/blob/trunk/src/gnuwin32/Makefile