emmake make command makes error when to build static library for openCV

576 views
Skip to first unread message

Joe

unread,
Apr 25, 2021, 8:11:47 AM4/25/21
to emscripten-discuss
Hello,

I am new to emscripten and cmake and  trying to make a simple application in cpp that uses openCV modules and compile it to wasm. I followed the documentation and tried to produce static library files *.a and the cpp file that references the opencv library as a .o file. This is where I had the error.

I ran the command
cmake ../ -B./ -DBUILD_SHARED_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64" -DWITH_1394=OFF -DWITH_FFMPEG=OFF -DBUILD_TESTS=OFF
to build opencv statically into the current folder which is inside the openCV folder. Then I ran the commands

  • make

  • sudo make install.   

after this I navigated to where my cpp file is cvcaller.cpp, then ran
  • cmake .

  • make
    based on this I get the executable. It all works well here. I ran the produced executable and it shows the value as it should.
    But when I ran the following commands instead based on the documentation here, I got the error.

    I cleared the folder which had the make files from before and ran the following commands.
  • emcmake cmake ../ -B./ -DBUILD_SHARED_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64" -DWITH_1394=OFF -
    DWITH_FFMPEG=OFF -DBUILD_TESTS=OFF

  • emmake make

error happens. I think the emcmake cmake is not working as it should in this case. 


make: make
Scanning dependencies of target gen-pkgconfig
[ 0%] Generate opencv.pc
[ 0%] Built target gen-pkgconfig
Scanning dependencies of target ittnotify
[ 0%] Building C object 3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o
In file included from /Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/3rdparty/ittnotify/src/ittnotify/ittnotify_static.c:59:
/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h:376:12: error: implicit declaration of function 'TBB_machine_fetchadd4' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
return TBB_machine_fetchadd4(ptr, 1) + 1L;
^
1 error generated.
emcc: error: '/Users/atul109/MyDocuments/work/new/emscripten_playground/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -D__EMSCRIPTEN_PTHREADS
=1 -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major
=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=17 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/atul109/MyDocuments/work/new/emscripten_playground/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/3rdparty/ittnotify/include -I/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/WasmBuild/3rdparty/ippicv/ippicv_lnx/icv/include -I/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/WasmBuild/3rdparty/ippicv/ippicv_lnx/iw/include -I/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/WasmBuild -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -pthread -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-implicit-fallthrough -Wno-undef -Wno-sign-compare -O3 -DNDEBUG -DNDEBUG -fPIC -c -pthread /Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/3rdparty/ittnotify/src/ittnotify/ittnotify_static.c -o CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o' failed (1)
make[2]: *** [3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o] Error 1
make[1]: *** [3rdparty/ittnotify/CMakeFiles/ittnotify.dir/all] Error 2
make: *** [all] Error 2
emmake: error: 'make' failed (2)

From what I understand the ittnotify is causing error. But somehow it was fine when I did the normal cmake and make. It only does this for emcmake cmake and emmake make.

/Users/atul109/MyDocuments/work/new/emscripten_playground/opencv-3.4.14/3rdparty/ittnotify/src/ittnotify/ittnotify_config.h:376:12: error: implicit declaration of function '__TBB_machine_fetchadd4' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
return __TBB_machine_fetchadd4(ptr, 1) + 1L;
^
1 error generated.

Please help. I am stuck on this for a while now and have no clue as to what to do to get my cpp application run as wasm in browser because it has opencv modules in it. using openCV.js and calling it's functions through js is not an option for me.

Thanks.

Floh

unread,
Apr 26, 2021, 10:47:28 AM4/26/21
to emscripten-discuss
The function TBB_machine_fetchadd4() looks like it's from Intel TBB library (https://en.wikipedia.org/wiki/Threading_Building_Blocks), I doubt TBB works as is on WASM. 

I would look for a cmake config option similar to "-DWITH_FFMPEG=OFF" which switches off TBB usage.

Also this part of the emcmake invokation doesn't look right:  -DCMAKE_OSX_ARCHITECTURES="x86_64" because you're not building for OSX (but emscripten), nor for x86_64 (but for WASM).

Did you check that OpenCV.js isn't actually compiled to WASM? The .js in the name doesn't necessarily mean that it is Javascript. For instance these build instructions for OpenCV.js have a lot of "wasm" in their build command options ;)


Floh

unread,
Apr 26, 2021, 10:58:06 AM4/26/21
to emscripten-discuss
PS: I just realized that I misunderstood last part about OpenCV.js.

But if OpenCV.js can be built for WASM callable from JS, I'd imagine that creating a static WASM library instead should be quite trivial (maybe there's even already a build option for it).

Reply all
Reply to author
Forward
0 new messages