emscripten-core / emscripten-core/emscripten
using with opencv 4.5 give compile error like "undefined symbol: __cxa_can_catch (referenced by __cxa_find_matching_catch_2__deps: ['$exceptionLast','$ExceptionInfo','__resumeException','__cxa_can_catch'], referenced by top-level compiled C/C++ code)"
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I develope an ionic app project. And I want to use opencv in this project to image processing. So I want to use opencv with C++ and compile with emscripten.
Here is my sample cpp code.
```
#include
#include
#include
#include
#include
using namespace emscripten;
using namespace cv;
extern "C"{
int EMSCRIPTEN_KEEPALIVE testFunction(uint8_t* buffertemp,size_t sizetemp ) {
const int width = 1280;
const int height = 800;
uint8_t* buffer;
size_t size;
cv::Mat mat_src = cv::Mat(height*1.5, width, CV_8UC1, buffer);
cv::Mat mat_dst = cv::Mat(height, width, CV_8UC3);
cv::cvtColor(mat_src, mat_dst, cv::COLOR_YUV2BGR_NV21);
cv::imwrite("yuv.png", mat_dst);
return 0;
}
}
```
Here is my compile command emcc setting
```
-oDecodeYuv420ToRGB.js
-sWASM=1
-sMODULARIZE=1
-s-lembind
"C:/Users/POLAT-PC/Documents/My-All-Projects/ImageProcesswithWebAssembly/pge-template-project/include/libopencv_world.a"
"C:/Users/POLAT-PC/Documents/My-All-Projects/ImageProcesswithWebAssembly/pge-template-project/include/liblibopenjp2.a"
"C:/Users/POLAT-PC/Documents/My-All-Projects/ImageProcesswithWebAssembly/pge-template-project/include/libzlib.a"
# -sERROR_ON_UNDEFINED_SYMBOLS=0
-s"EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap', 'malloc', '_malloc']"
-sEXPORT_ALL=1
# -sNO_DISABLE_EXCEPTION_CATCHING=1
-sDISABLE_EXCEPTION_CATCHING=2
-sUSE_ZLIB=1
-sALLOW_MEMORY_GROWTH=1
-sMAX_WEBGL_VERSION=2
-sMIN_WEBGL_VERSION=2
-sUSE_LIBPNG=1
-sUSE_SDL_MIXER=2 # thanks for the s, cstd
-sLLD_REPORT_UNDEFINED
```
Here is my ionic side code
```
sendArrayBuffertWasm(input):Observable{
return this.wasmReady.pipe(filter(value => value === true)).pipe(
map(() => {
var numBytes = input.length * input.BYTES_PER_ELEMENT;
const dataPtr = this.module.__zone_symbol__value._malloc(numBytes);
const dataOnHeap = new Uint8Array(this.module.__zone_symbol__value.HEAPU8.buffer, dataPtr, numBytes);
dataOnHeap.set(input);
return this.module.__zone_symbol__value._checkImageQuality(dataOnHeap.byteOffset, input.length);
})
);
}
```
In here the openCV wasm file which is "libopencv_world.a,liblibopenjp2.a and libzlib.a " created from OpenCV 4.5 githup repo. To cereate openCV wasm file, I following the steps in https://blog.seeso.io/face-detection-on-web-tflite-wasm-simd-462975e0f628
The problem is when I compiling with emcc, throw an error like below
> error: undefined symbol: __cxa_can_catch (referenced by __cxa_find_matching_catch_2__deps: ['$exceptionLast','$ExceptionInfo','__resumeException','__cxa_can_catch'], referenced by top-level compiled C/C++ code)
> warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
> warning: ___cxa_can_catch may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
> Error: Aborting compilation due to previous errors
> em++: error: 'C:/Users/POLAT-PC/AppData/Local/emsdk/node/14.18.2_64bit/bin/node.exe C:\Users\POLAT-PC\AppData\Local\emsdk\upstream\emscripten\src\compiler.js C:\Users\POLAT-PC\AppData\Local\Temp\tmp__qv7n01.json' failed (returned 1)
> mingw32-make[2]: *** [CMakeFiles\DecodeYuv420ToRGB.dir\build.make:115: bin/DecodeYuv420ToRGB.js] Error 1
> mingw32-make[1]: *** [CMakeFiles\Makefile2:83: CMakeFiles/DecodeYuv420ToRGB.dir/all] Error 2
> mingw32-make: *** [Makefile:90: all] Error 2
If I remove openCV codes from cpp file, it is compiled sucessfully. or If I remove extern "C" tag from cpp file , it is compiled successfully but in ionic project give error like testFunction is not a function. If I added -sERROR_ON_UNDEFINED_SYMBOLS=0 to emcc setting, it is compiled successfully but in ionic project it gives following error
> home.page.ts:56 ERROR 8524992 - Exception catching is disabled, this exception cannot be caught. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch.
If I set -sNO_DISABLE_EXCEPTION_CATCHING=1 emcc setting, and remove -sDISABLE_EXCEPTION_CATCHING=2 , in ionic project it gives error only ERROR 8524992 and nothing else.
I have searched all page in internet for two week but I can't solve problem. Please tell me where is my mistake. Thank you for your help.
Contributor guide
Assessment
This issue has not been assessed yet.