emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.77k stars 3.3k forks source link

missing function #18714

Open emirdeliz opened 1 year ago

emirdeliz commented 1 year ago

Please include the following in your bug report:

Version of emscripten/emsdk:

3.1.31 (e88336121cfe6da4a96c88e46f314552f07dfed0)
clang version 17.0.0 (https://github.com/llvm/llvm-project 1142e6c7c795de7f80774325a07ed49bc95a48c9)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
emcc \
  webassembly/cpp/brisk-detector.cpp \
  -I /main/opencv/include \
  -I /main/opencv/build_wasm \
  -I /main/opencv/modules/calib3d/include \
  -I /main/opencv/modules/core/include \
  -I /main/opencv/modules/dnn/include \
  -I /main/opencv/modules/features2d/include \
  -I /main/opencv/modules/flann/include \
  -I /main/opencv/modules/gapi/include \
  -I /main/opencv/modules/highgui/include \
  -I /main/opencv/modules/imgcodecs/include \
  -I /main/opencv/modules/imgproc/include \
  -I /main/opencv/modules/ml/include \
  -I /main/opencv/modules/objdetect/include \
  -I /main/opencv/modules/photo/include \
  -I /main/opencv/modules/stitching/include \
  -I /main/opencv/modules/ts/include \
  -I /main/opencv/modules/video/include \
  -I /main/opencv/modules/videoio/include \
  -I /main/opencv/modules/world/include \
  -Os -g0 -Wall --no-entry --profiling-funcs \
  -s WARN_ON_UNDEFINED_SYMBOLS=0 \
  -s MINIMAL_RUNTIME=1 \
  -s EXPORT_NAME="cdecode" \
  -s FULL_ES3=1 \
  -o dist/webassembly/object-detector-on-image-cpp.html

About my scenario. I try to use opencv(cpp) with webassembly. So when the compile is done I get the errors on output js like below:

function __ZN2cv17DescriptorMatcher6createERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE() {
    err("missing function: _ZN2cv17DescriptorMatcher6createERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE");
    abort(-1)
}

function __ZN2cv3MatC1ERKS0_() {
    err("missing function: _ZN2cv3MatC1ERKS0_");
    abort(-1)
}

function __ZN2cv3MatC1Eiii() {
    err("missing function: _ZN2cv3MatC1Eiii");
    abort(-1)
}

function __ZN2cv3MatC1EiiiPvm() {
    err("missing function: _ZN2cv3MatC1EiiiPvm");
    abort(-1)
}

function __ZN2cv3MatC1Ev() {
    err("missing function: _ZN2cv3MatC1Ev");
    abort(-1)
}

function __ZN2cv3MatD1Ev() {
    err("missing function: _ZN2cv3MatD1Ev");
    abort(-1)
}

function __ZN2cv5BRISK6createEiif() {
    err("missing function: _ZN2cv5BRISK6createEiif");
    abort(-1)
}

function __ZN2cv7sortIdxERKNS_11_InputArrayERKNS_12_OutputArrayEi() {
    err("missing function: _ZN2cv7sortIdxERKNS_11_InputArrayERKNS_12_OutputArrayEi");
    abort(-1)
}

function __ZNK2cv17DescriptorMatcher5matchERKNS_11_InputArrayES3_RNSt3__26vectorINS_6DMatchENS4_9allocatorIS6_EEEES3_() {
    err("missing function: _ZNK2cv17DescriptorMatcher5matchERKNS_11_InputArrayES3_RNSt3__26vectorINS_6DMatchENS4_9allocatorIS6_EEEES3_");
    abort(-1)
}

I'm running using vs code container. The image is emirdeliz/cpp-opencv-node-emscripten and platform linux/amd64. My project is: https://github.com/emirdeliz/object-detector-image-webassembly

So what's the problem?

iliakan commented 1 year ago

Did you label functions as extern C ?

iliakan commented 1 year ago

I never compiled CPP, but I saw many notes about adding extern C to prevent name mangling.

sbc100 commented 1 year ago

the best thing to is probably to remove -sWARN_ON_UNDEFINED_SYMBOLS=0.. then those missing symbols will become build errors and you can work on figuring out how to include them in your project.

It looks like you need to actually include the opencv library code somehow, most likely as library file at link time.

emirdeliz commented 1 year ago

I never compiled CPP, but I saw many notes about adding extern C to prevent name mangling.

I need to compare two images using opencv. After comparing, I return a complex object to js. The problem is that extern C only returns C types. So it's not possible to use an extern in this case.