简体   繁体   中英

Why won't emscripten compile my functions?

I'm trying to compile some c++ code in to a wasm binary with functions included. However, even though I don't get any compilation errors or any other warnings during compilation, the files generated by emscripten don't include the functions I exported with "-s EXPORTED_FUNCTIONS=['....']"

Here's the file with functions I want to export: https://pastebin.com/B5w1R4BC

Here's the compilation command I'm using:

em++ -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 \
-Igameoflife/include -Os -DNDEBUG \
-s EXPORTED_FUNCTIONS="['_GOL_Instance_new', '_GOL_Instance_destroy', '_GOL_Init', '_GOL_Step', '_GOL_get_values']" \
-o gol.js gameoflife/src/cellmap.cpp bridge.cpp

Which runs without any issues.

However, when I import 'gol.js' into javascript, the Module object does not have access to any of the functions I'm trying to include (I am waiting for the module to get initialized before calling those functions).

TypeError: Module._GOL_Instance_new is not a function

Why can't I access these functions through wasm?

They're likely being mangled by your C++ compiler. Declare them as extern "C" to avoid this:

extern "C"
GOL_Instance *
GOL_Instance_new() {
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM