导出所有函数的一种方法是使用-s LINKABLE=1
https://github.com/kripken/emscripten/blob/1.34.12/src/settings.js#L461 https://github.com/kripken/emscripten/blob/1.34.12/src/settings.js#L461 and -s EXPORT_ALL=1
https://github.com/kripken/emscripten/blob/1.34.12/src/settings.js#L385 https://github.com/kripken/emscripten/blob/1.34.12/src/settings.js#L385编译时的选项。
emcc tests/hello_function.cpp -o function.html -s LINKABLE=1 -s EXPORT_ALL=1
只是有-s EXPORT_ALL=1
确实有效,但在我的系统上会出现以下警告:
warning: unresolved symbol: remquof
warning: unresolved symbol: ilogb
warning: unresolved symbol: nextafter
warning: unresolved symbol: remquo
warning: unresolved symbol: fesetround
warning: unresolved symbol: llvm_fma_f64
但是,这并不能完全满足您的需求,因为 libc 函数也会被导出。例如,您可以调用
Module.ccall('printf', 'number', ['string'], ['Passing a string from Javascript to C\n');
很好,它会将字符串发送到标准输出(默认情况下只是浏览器控制台)。
这个答案是基于@zakki的回答 https://stackoverflow.com/a/33206957/1319998.