The Module object definitely needs to exist before including the main .js file, otherwise the startup sequence won't connect to the right object. I.e. the "Html file generating the error:" will not be possible to work. I suppose changing to the working html file resolved all the issues here(?)
2017-09-15 20:49 GMT+03:00 Dirk Vanden Boer <dirk....@gmail.com>: > My minimal reproduction scenario: > > C++ source (asmerror.cpp): > #include <emscripten/bind.h> > #include <iostream> > > static void hello() { > std::cout << "Hello wasm\n"; > } > > EMSCRIPTEN_BINDINGS(asmerror) { > emscripten::function("hello", &hello); > } > > Html file generating the error: > <!doctype html> > <html> > <head><meta charset="UTF-8"></head> > <body> > <script type="text/javascript" src="asmerror.js"></script> > <script type="text/javascript"> > var Module = { > print: function(text) { console.log(text); }, > printErr: function(text) { console.error(text); }, > onRuntimeInitialized: function() { > console.log("onRuntimeInitialized"); > Module.hello(); > } > }; > </script> > </body> > </html> > > Html file that works: > <!doctype html> > <html> > <head><meta charset="UTF-8"></head> > <body> > <script type="text/javascript"> > var Module = { > print: function(text) { console.log(text); }, > printErr: function(text) { console.error(text); }, > onRuntimeInitialized: function() { > console.log("onRuntimeInitialized"); > Module.hello(); > } > }; > </script> > <script type="text/javascript" src="asmerror.js"></script> > </body> > </html> > > > CMakeLists.txt file to create webassembly (emcmake cmake .): > > cmake_minimum_required(VERSION 3.0) > project(asmerror) > set(CMAKE_CXX_STANDARD 11) > set(CMAKE_CXX_EXTENSIONS OFF) > find_program (EMCC emcc) > if (NOT EMCC) > message(FATAL_ERROR "Could not find emcc executable") > endif () > > add_library(asmerror SHARED > asmerror.cpp > ) > > set_target_properties(asmerror PROPERTIES SUFFIX .bc) > > get_target_property(WASM_DIR asmerror ARCHIVE_OUTPUT_DIRECTORY) > get_target_property(WASM_MODULE asmerror OUTPUT_NAME) > > add_custom_command(TARGET asmerror > POST_BUILD > COMMAND ${EMCC} > ARGS > -O3 > -s WASM=1 > -s TOTAL_MEMORY=96468992 > -s DISABLE_EXCEPTION_CATCHING=0 > -s ASSERTIONS=1 > --llvm-lto 1 > --bind > $<TARGET_FILE:asmerror> > -o $<TARGET_FILE_DIR:asmerror>/asmerror.js > BYPRODUCTS > ${CMAKE_BINARY_DIR}/asmerror.js > ${CMAKE_BINARY_DIR}/asmerror.wasm > COMMENT "Generating webassembly" > ) > > Hope this is clear > > -- > 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-discuss+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.