2015-02-17 32 views
3

我正在嘗試使用Emscripten編譯一些用C語言編寫的R函數。我的第一個任務是移植一個名爲pf的函數。使用Emscripten將R函數編譯爲JavaScript

來源可以找到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

如果你想使用gnuwin32/fixed/h/config.h,需要-DHAVE_CONFIG_H

https://github.com/wch/r-source/blob/trunk/src/gnuwin32/Makefile

+0

謝謝,很好的信息。但是,這並沒有多大幫助。我從運行'。/ configure'得到了一個非windows config.h,並且現在使用-DHAVE_CONFIG_H來包含它,但問題依然存在。 – 2015-02-23 02:26:46

相關問題