# Undefined symbol when using VideoCapture in WebAssembly

**URL:** <https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147>\
**Category:** C++\
**Tags:** opencvjs, build, videoio\
**Created:** [July 3, 2021, 4:36am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147 "2021-07-03T04:36:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongzi](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hongzi](https://forum.opencv.org/u/hongzi)\
**Post date:** [July 3, 2021, 4:36am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147/1 "2021-07-03T04:36:37Z")

</div>

I was trying to use OpenCV’s video capture on C++ side of wsam, but the emcc compiler can’t find a symbol. Minimal `video.cc` example as below

```auto
#include <opencv2/highgui.hpp>

int main() {
  cv::VideoCapture("./video.mp4"); 
}

```

I can compile with g++ (version 12.0.5):

```auto
 g++ -O3 `pkg-config --cflags --libs opencv4` -std=c++17 video.cc

```

But when using emcc (version 2.0.25):

```auto
emcc -O3 `pkg-config --cflags --libs opencv4` -std=c++17 video.cc

```

I got an error

```auto
error: undefined symbol: _ZN2cv12VideoCaptureC1ERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN2cv12VideoCaptureC1ERKNSt3__ 212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors

```

Searched over the Internet, saw a few similar questions (same undefined symbols), but couldn’t find an answer.

Can anyone share some ideas about solving this issue? Really appreciate the help!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 3, 2021, 6:30am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147/2 "2021-07-03T06:30:46Z")

</div>

not a js user, but afaik, you have to use [the javascript emulation here](https://github.com/opencv/opencv/blob/821fae0d94a06105402b38c482cc84efbdd27b7b/modules/js/src/helpers.js#L118) and the c++ version is not available (the whole videoio module is excluded from the js build)

---

<div class="post-metadata">

**Author:** ![hongzi](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hongzi](https://forum.opencv.org/u/hongzi)\
**Post date:** [July 3, 2021, 7:23am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147/3 "2021-07-03T07:23:36Z")

</div>

Thanks a lot for he reply! This is my guess too. Any reason the videoio module is excluded - is there a plan brining it in?

I’m basically now trying to emcc build videoio module together with the code that uses cv::VideoCapture. It’s a painful process tbh…

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 3, 2021, 7:58am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147/4 "2021-07-03T07:58:36Z")

</div>

> [@hongzi](#):
>
> Any reason the videoio module is excluded

i can only guess, but the videoio is not doing much on its own, but heavily relies on external libs like v4l, ffmpeg or gstreamer

> [@hongzi](#):
>
> is there a plan brining it in?

i don’t think so, [but have a look here](https://github.com/opencv/opencv/issues/19744)

---

<div class="post-metadata">

**Author:** ![hongzi](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hongzi](https://forum.opencv.org/u/hongzi)\
**Post date:** [July 3, 2021, 8:00am UTC](https://forum.opencv.org/t/undefined-symbol-when-using-videocapture-in-webassembly/4147/5 "2021-07-03T08:00:49Z")

</div>

ok so I set `"-DBUILD_opencv_videoio=ON"` in `opencv/platforms/js/build_js.py`, then rebuild the js build. The build was successful.

I was hoping `libopencv_videoio.a` to appear but it is not in `opencv/platforms/js/build_wasm/lib/*.a`.

So linking to `opencv/platforms/js/build_wasm/lib/*.a` still has the same missing symbol.

But stepping back, what I want to have is an efficient video format to do some editing on the C++ side. I could load a video on js and then send all the frames as images to C++. Or I could load videos from file using ffmpeg. But I guess the problem would be that many of the functions in opencv’s video module take as input VideoCapture object. To really use opencv library for videos, I may have to use VideoCapture to load video in the first step. Is my assessment accurate?
