如何为C库编写自定义Emscripten填充程序?Emscripten捆绑了某些C库(如SDL和OpenAL)的填充程序,但是对于其他库,您将不得不自己动手.
通过shim我的意思是,一个C库的JavaScript替换要移植的代码取决于.
Emscripten有关于这个主题的一些文档,尽管在撰写本文时它有些不完整.
首先,你需要在JavaScript中编写一个Emscripten"库",我们假设相应的C库被称为Example:
example.js:
// "use strict";
var LibraryExample = {
// Internal functions
$EXAMPLE: {
internal_func: function () {
}
},
example_initialize: function (arg) {
EXAMPLE.internal_func()
}
}
autoAddDeps(LibraryExample, '$EXAMPLE')
mergeInto(LibraryManager.library, LibraryExample)
Run Code Online (Sandbox Code Playgroud)
其次,您必须通过emcc的--js-library选项将example.js文件集成到构建中:
emcc --js-library shims/example.js -o project.js project.bc
Run Code Online (Sandbox Code Playgroud)
现在该函数example_initialize应该可用于Emscripten生成的JS代码,从而替换C库依赖项.