klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

emsdk编译cpp为wasm #771

Open klren0312 opened 11 months ago

klren0312 commented 11 months ago

使用容器来避免环境安装和冲突问题

podman run   --rm   -v $(pwd):/src   trzeci/emscripten   emcc -o ./appWASM.js ./emscripten.cpp -O3 -s ALLOW_MEMORY_GROWTH=1 -s USE_WEBGL2=1 -s FULL_ES3=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -std=c++1z -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']"
klren0312 commented 11 months ago

问题1

Uncaught TypeError: Module.ccall is not a function

参考资料

https://github.com/emscripten-core/emscripten/issues/6021#issuecomment-355107917 image

klren0312 commented 11 months ago

问题二

Module._malloc is not a function

解决

改用 -o2

参考资料

1697447731113

https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#3131---012623