EdwardLu2018 / wasm-ar

Playing around with Augmented Reality on the Web using OpenCV and WebAssembly
https://edwardlu2018.github.io/wasm-ar/
52 stars 19 forks source link

Prevent name mangling in initAR, track and resetTracking #12

Closed kalwalt closed 3 years ago

kalwalt commented 3 years ago

The functions initAR, track and resetTracking are invoked with an Emscripten cwrap function with mangled names for example initAR is invoked with https://github.com/EdwardLu2018/wasm-ar/blob/76b749b48c8170fda9d2de3c1f85d98b40c46a98/js/image-tracker.js#L22 note "_Z6initARPhmm" that happens because the three functions are not wrapped inside a

extern "C" {
 } 

to prevent C++ name mangling as described in https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html?highlight=cwrap#calling-compiled-c-functions-from-javascript-using-ccall-cwrap and add those function to the -s EXPORTED_FUNCTIONS='['_malloc', '_free', '_initAR', '_track', '_resetTracking']' @EdwardLu2018 I would submit a PR if you agree.

EdwardLu2018 commented 3 years ago

Ohhh, I see. Thanks for pointing this out, feel free to make a PR for this!

EdwardLu2018 commented 3 years ago

Added this in https://github.com/EdwardLu2018/wasm-ar/commit/db376bf73b63b85a3938b4c36ee5d95d72f76618

kalwalt commented 3 years ago

@EdwardLu2018 Does it works? Without adding -s EXPORTED_FUNCTIONS='['_malloc', '_free', '_initAR', '_track', '_resetTracking']' ?

EdwardLu2018 commented 3 years ago

It should, because I had EMSCRIPTEN_KEEPALIVE before each of those exported function definitions. I believe it still works

kalwalt commented 3 years ago

It should, because I had EMSCRIPTEN_KEEPALIVE before each of those exported function definitions. I believe it still works

Ok i will test your changes :smiley:

kalwalt commented 3 years ago

You are right, It's not necessary. we can close this.

datased2019 commented 3 years ago

I have encounter the problem after compiled. Any Comments? image

kalwalt commented 3 years ago

I have encounter the problem after compiled. Any Comments? image

It could depends by which emcc version are you used to build the libs, I have used emcc 2.0.20 version, consider that previous version may have slightly differences. Have you also run the npm run build command?

EdwardLu2018 commented 3 years ago

Maybe try cleaning your build folder or your browser cache? @kalwalt Does the latest version work for you?

kalwalt commented 3 years ago

Maybe try cleaning your build folder or your browser cache? @kalwalt Does the latest version work for you?

@EdwardLu2018 I will check again when i have time. :smile:

datased2019 commented 3 years ago

Sorry. My bad. I just got some files changed and didn't notice that. It's working. Pls close it. Thx.