问题
I'm trying to compile some R functions, written in C, to JavaScript using Emscripten. My first mission is to port a function called pf
.
The source can be found here. So, I go into the src directory and try running:
(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
I get a function _Rf_pf
in the output JavaScript. I can actually call this function and it returns a result. But, because R_PosInf
and company are not resolved, it short circuits on R_P_bounds_01(x, 0., ML_POSINF);
. ML_POSINF
is somehow set to 0 giving weird results. So, the heart of the algorithm is not executed.
Does anyone know how I can get these symbols resolved and get this function ported?
I can try to compile more source and that seems to get me somewhere:
$ 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
But, this seems to lead me down a huge rabbit hole. And, then, I hit some snags:
$ 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=]
Note that I have CPATH set. I don't know if this is the way to go about pointing the compiler to different headers I need:
(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
回答1:
If you want to use gnuwin32/fixed/h/config.h
, -DHAVE_CONFIG_H
is needed.
https://github.com/wch/r-source/blob/trunk/src/gnuwin32/Makefile
来源:https://stackoverflow.com/questions/28573314/compiling-r-functions-to-javascript-with-emscripten