Search code examples
c++windowsopencvdlibwebassembly

Problem in compilation of C++ code to WASM using emcc


I am trying to compile the C++ code to WASM but facing problems in it. My C++ code included dlib and OpenCV libraries. I have successfully compiled OpenCV and dlib for C++ environment. Also, I have installed emscripten in my system.

The directory structure is

C Drive

|..

|-- dlib

|-- emsdk

|-- opencv

|-- cpp_project

now when I am inside the cpp_project dir in command prompt (open in admin mode) I am executing the following command.

emcc -msse3 -msimd128 -std=c++11 -O3 -I ../dlib ../opencv/build/include/opencv2/core.hpp ../dlib/dlib/all/source.cpp -lstdc++ -lpthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s TOTAL_MEMORY=1024MB -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s WASM=1 -o main.js

I am getting the following error:

../opencv/build/include/opencv2/core.hpp:52:10: fatal error: 'opencv2/core/cvdef.h' file not found

#include "opencv2/core/cvdef.h" ^~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

Please help me.


Solution

  • You have to change -I ../dlib ../opencv/build/include/opencv2/core.hpp to -I ../dlib -I ../opencv/build/include