Difficulty linking in embind-generated bindings

35 views
Skip to first unread message

Michael....@nasa.gov

unread,
Jul 24, 2020, 5:58:41 PM7/24/20
to emscripten-discuss
Hello!

I’m experimenting with converting an existing project here to WebAssembly.  This project has several modules, each with its own library and test executable.  My current approach, just to see if I can get things running, is to build those test executables using the default emscripten shell.html file.  That process has been successful so far, except when I try to add a binding via embind.  Trying to “link” in the generated .js file with --post-js results in a runtime error apparently before any of the project code is run: “Module.arguments has been replaced with plain arguments_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)”

I have this relevant section of my CMakeLists file:

  add_custom_command(OUTPUT Utils-bindings.js

    COMMAND

    ${CMAKE_CXX_COMPILER}

    --bind

    “${CMAKE_CURRENT_SOURCE_DIR}/base/emscripten.cc”

    -o

    Utils-bindings.js

    DEPENDS

    “${CMAKE_CURRENT_SOURCE_DIR}/base/emscripten.cc”

    )

  target_link_options(${Utils_TEST} PUBLIC --bind --post-js Utils-bindings.js)

 

Which generates these commands:

 em++ --bind base/emscripten.cc -o Utils-bindings.js

em++  -s DISABLE_EXCEPTION_CATCHING=2 -s WASM=1 -s SAFE_HEAP=1 -s WARN_UNALIGNED=1 -fsanitize=undefined -Oz -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 -g -Wall -fno-omit-frame-pointer -m32 --bind --post-js Utils-bindings.js @CMakeFiles/Utils-test_g.dir/objects1.rsp  -o Utils-test_g.html @CMakeFiles/Utils-test_g.dir/linklibs.rsp

Loading Utils-test_g.html in a browser produces the error.  I’ve tried all of the --(extern-)?(pre|post)-js permutations without success.  I’m well out of my depth and have been trying whatever I can find at this point.  How do I get these library bindings “linked” into the “executable”?  

Thanks!

~Michael Iatauro

Sam Clegg

unread,
Jul 26, 2020, 12:50:55 PM7/26/20
to emscripte...@googlegroups.com
On Fri, Jul 24, 2020 at 2:58 PM 'Michael....@nasa.gov' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Hello!

I’m experimenting with converting an existing project here to WebAssembly.  This project has several modules, each with its own library and test executable.  My current approach, just to see if I can get things running, is to build those test executables using the default emscripten shell.html file.  That process has been successful so far, except when I try to add a binding via embind.  Trying to “link” in the generated .js file with --post-js results in a runtime error apparently before any of the project code is run: “Module.arguments has been replaced with plain arguments_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)”

I have this relevant section of my CMakeLists file:

  add_custom_command(OUTPUT Utils-bindings.js

    COMMAND

    ${CMAKE_CXX_COMPILER}

    --bind

    “${CMAKE_CURRENT_SOURCE_DIR}/base/emscripten.cc”

    -o

    Utils-bindings.js

    DEPENDS

    “${CMAKE_CURRENT_SOURCE_DIR}/base/emscripten.cc”

    )

  target_link_options(${Utils_TEST} PUBLIC --bind --post-js Utils-bindings.js)

 

Which generates these commands:

 em++ --bind base/emscripten.cc -o Utils-bindings.js


You probably want  to use `-c` here to compile `base/emscripten.cc` into an object file, and the link that object file into your final binary.

Otherwise you are asking emscripten to produce a filly linked program here, that that cannot be combined into another emscripten program.

 

em++  -s DISABLE_EXCEPTION_CATCHING=2 -s WASM=1 -s SAFE_HEAP=1 -s WARN_UNALIGNED=1 -fsanitize=undefined -Oz -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 -g -Wall -fno-omit-frame-pointer -m32 --bind --post-js Utils-bindings.js @CMakeFiles/Utils-test_g.dir/objects1.rsp  -o Utils-test_g.html @CMakeFiles/Utils-test_g.dir/linklibs.rsp

Loading Utils-test_g.html in a browser produces the error.  I’ve tried all of the --(extern-)?(pre|post)-js permutations without success.  I’m well out of my depth and have been trying whatever I can find at this point.  How do I get these library bindings “linked” into the “executable”?  

Thanks!

~Michael Iatauro

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/27a6a725-37f0-4e29-a2ee-b5d47deaeee4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages