Building mageslam to WASM

Hello,

I’m currently trying to compile the mageslam repository found here GitHub - syntheticmagus/mageslam: A lightweight monocular SLAM written in C++ by @syntheticmagus to a wasm and was hoping to maybe get some hints since I’m a bit stuck at the moment.

Steps I’ve taken so far:

  • create unix makefiles using the following command emcmake cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=MinSizeRel -D OpenCV_DIR="C:\path\to\unix\opencv-3.4.3\build" ..
  • build to libmageslam_c_api_s.a by running cmake --build .

Currently stuck at compiling the lib to a wasm module using emcc using commands like:

emcc --emit-symbol-map -g2 -sLLD_REPORT_UNDEFINED -I C:/git/mageslam/Build/Core/MAGESLAM/libMAGESLAM_s.a -sEXPORTED_FUNCTIONS=_mageslam_process_frame libmageslam_c_api_s.a -o wasm/libmageslam.html

Getting a bunch of errors like the following:

wasm-ld: error: libmageslam_c_api_s.a(mageslam_c_api.cpp.o): undefined symbol: cv::Mat::Mat(int, int, int, void*, unsigned long)
wasm-ld: error: libmageslam_c_api_s.a(mageslam_c_api.cpp.o): undefined symbol: mage::MAGESlam::ProcessFrame(mage::MAGESlam::Frame const&)

My questions are:

  • is the general process I’ve taken so far correct (compiling makefiles to unix → building static lib → compiling lib to wasm) ?
  • how does the final build stage work / how do I tell / link emcc where to find the missing symbols. I hope I can figure out the details on my own but am generally not sure if I’m on the right track right now (simple examples work fine but this is the first time I’m trying to compile an existing / actual project to wasm)

Thanks everyone in advance!

1 Like

cc @BabylonNative FYI

2 Likes

cc @syntheticmagus

1 Like

Please compile opencv with build_js, then -D OpenCV_DIR=“C:\path\to\unix\opencv-3.4.3\build_js” …
docs: OpenCV: Build OpenCV.js

This is not for the same engine