title: opencv wasm build fails on windows
body: <p>I am trying to build the wasm version of OpenCV 4.0.0 on Windows 10 and I cannot succeed. I read a lot of posts about similar issues here and on github issue pages about both opencv and emscripten, tried the suggested solutions but none seems to work for me.</p>
  
  <p>My setup is:<br>
  OS - Windows 10 64-bit<br>
  OpenCV - v4.0.0 (stable) - I tried cloning from <a href="https://github.com/opencv/opencv" rel="nofollow noreferrer">github</a> and downloading prebuilt binaries, also v3.4.5<br>
  emscripten - v1.38.22<br>
  python - bundled with emscripten (2.7.13.1_64bit), also tried 3.6.4<br>
  C++ compiler - minGW64<br>
  cmake - 3.13.0<br>
  openCL headers - from <a href="https://github.com/KhronosGroup/OpenCL-Headers" rel="nofollow noreferrer">github</a><br>
  binaryen - version_63 from <a href="https://github.com/WebAssembly/binaryen" rel="nofollow noreferrer">github</a> - I also tried installing it with emsdk install command<br>
  git - GitBash windows version  </p>
  
  <p>Things that DO work:<br>
  - cmake (in GUI and command line, as some posts suggest)<br>
  - minGW64 g++ can generate proper executables for win64<br>
  - opencv works with g++<br>
  - emscripten can compile [hello world].cpp  </p>
  
  <p>Things that DO NOT work:<br>
  - emscripten fails to generate LLVM bitcode from opencv library but works fine for zlib - here I followed instructions from <a href="https://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html" rel="nofollow noreferrer">emscripten docs</a><br>
  - it also fails to compile a simple .cpp file that uses opencv functions like imread and imshow:</p>
  
  <pre><code>error: undefined symbol: _ZN2cv17destroyAllWindowsEv
  warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
  error: undefined symbol: _ZN2cv3Mat10deallocateEv
  error: undefined symbol: _ZN2cv6imreadERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
  error: undefined symbol: _ZN2cv6imshowERKNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_11_InputArrayE
  error: undefined symbol: _ZN2cv7waitKeyEi
  error: undefined symbol: _ZN2cv8fastFreeEPv
  error: undefined symbol: _ZN2cv9thresholdERKNS_11_InputArrayERKNS_12_OutputArrayEddi
  Error: Aborting compilation due to previous errors
  </code></pre>
  
  <p>Here I tried the flag <code>-s ERROR_ON_UNDEFINED_SYMBOLS=0</code> as suggested in github issues and it indeed turned the errors to warnings but the resulting .js still doesn't work and finds these exact errors as undefined functions.</p>
  
  <p>When I try to <strong>build opencv.js with or without <code>--build_wasm</code> option</strong> I get:</p>
  
  <pre><code>C:\opencv&gt;python platforms\js\build_js.py build_wasm --build_wasm --emscripten_dir d:\Download\gitEMSDK\emsdk\emscripten\1.38.22
  Args: Namespace(build_dir='build_wasm', build_doc=False, build_test=False, build_wasm=True, clean_build_dir=False, config_only=False, disable_wasm=False, emscripten_dir='d:\\Download\\gitEMSDK\\emsdk\\emscripten\\1.38.22', enable_exception=False, opencv_dir='C:\\opencv', skip_config=False)
  Check dir C:\opencv\build_wasm (create: True, clean: False)
  Check dir C:\opencv (create: False, clean: False)
  Check dir d:\Download\gitEMSDK\emsdk\emscripten\1.38.22 (create: False, clean: False)
  =====
  ===== Config OpenCV.js build for wasm
  =====
  Executing: ['cmake', '-DCMAKE_BUILD_TYPE=Release', "-DCMAKE_TOOLCHAIN_FILE='d:\\Download\\gitEMSDK\\emsdk\\emscripten\\1.38.22\\cmake\\Modules\\Platform\\Emscripten.cmake'", "-DCPU_BASELINE=''", "-DCPU_DISPATCH=''", '-DCV_TRACE=OFF', '-DBUILD_SHARED_LIBS=OFF', '-DWITH_1394=OFF', '-DWITH_ADE=OFF', '-DWITH_VTK=OFF', '-DWITH_EIGEN=OFF', '-DWITH_FFMPEG=OFF', '-DWITH_GSTREAMER=OFF', '-DWITH_GTK=OFF', '-DWITH_GTK_2_X=OFF', '-DWITH_IPP=OFF', '-DWITH_JASPER=OFF', '-DWITH_JPEG=OFF', '-DWITH_WEBP=OFF', '-DWITH_OPENEXR=OFF', '-DWITH_OPENGL=OFF', '-DWITH_OPENVX=OFF', '-DWITH_OPENNI=OFF', '-DWITH_OPENNI2=OFF', '-DWITH_PNG=OFF', '-DWITH_TBB=OFF', '-DWITH_PTHREADS_PF=OFF', '-DWITH_TIFF=OFF', '-DWITH_V4L=OFF', '-DWITH_OPENCL=OFF', '-DWITH_OPENCL_SVM=OFF', '-DWITH_OPENCLAMDFFT=OFF', '-DWITH_OPENCLAMDBLAS=OFF', '-DWITH_GPHOTO2=OFF', '-DWITH_LAPACK=OFF', '-DWITH_ITT=OFF', '-DBUILD_ZLIB=ON', '-DBUILD_opencv_apps=OFF', '-DBUILD_opencv_calib3d=ON', '-DBUILD_opencv_dnn=ON', '-DBUILD_opencv_features2d=ON', '-DBUILD_opencv_flann=ON', '-DBUILD_opencv_gapi=OFF', '-DBUILD_opencv_ml=OFF', '-DBUILD_opencv_photo=ON', '-DBUILD_opencv_imgcodecs=OFF', '-DBUILD_opencv_shape=OFF', '-DBUILD_opencv_videoio=OFF', '-DBUILD_opencv_videostab=OFF', '-DBUILD_opencv_highgui=OFF', '-DBUILD_opencv_superres=OFF', '-DBUILD_opencv_stitching=OFF', '-DBUILD_opencv_java=OFF', '-DBUILD_opencv_js=ON', '-DBUILD_opencv_python2=OFF', '-DBUILD_opencv_python3=OFF', '-DBUILD_EXAMPLES=OFF', '-DBUILD_PACKAGE=OFF', '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF', '-DBUILD_DOCS=OFF', "-DCMAKE_C_FLAGS='-s WASM=1 '", "-DCMAKE_CXX_FLAGS='-s WASM=1 '", 'C:\\opencv']
  Re-run cmake no build system arguments
  -- Building for: Visual Studio 15 2017
  -- Found PythonInterp: D:/Download/gitEMSDK/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe (found suitable version "2.7.13", minimum required is "2.7")
  -- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is at least version "2.7")
  -- Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)
  -- If you want to enable Python/Numpy support, set the following variables:
  --   PYTHON2_INCLUDE_PATH
  --   PYTHON2_LIBRARIES (optional on Unix-like systems)
  --   PYTHON2_NUMPY_INCLUDE_DIRS
  --   PYTHON3_INCLUDE_PATH
  --   PYTHON3_LIBRARIES (optional on Unix-like systems)
  --   PYTHON3_NUMPY_INCLUDE_DIRS
  -- Could NOT find PythonInterp: Found unsuitable version "2.7.13", but required is at least "3.2" (found D:/Download/gitEMSDK/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe)
  -- Performing Test HAVE_CXX_FSIGNED_CHAR
  -- Performing Test HAVE_CXX_FSIGNED_CHAR - Failed
  -- Performing Test HAVE_C_FSIGNED_CHAR
  -- Performing Test HAVE_C_FSIGNED_CHAR - Failed
  -- Performing Test HAVE_CXX_W
  -- Performing Test HAVE_CXX_W - Failed
  -- Performing Test HAVE_C_W
  -- Performing Test HAVE_C_W - Failed
  -- Performing Test HAVE_CXX_WALL
  -- Performing Test HAVE_CXX_WALL - Failed
  -- Performing Test HAVE_C_WALL
  -- Performing Test HAVE_C_WALL - Failed
  -- Performing Test HAVE_CXX_WERROR_RETURN_TYPE
  -- Performing Test HAVE_CXX_WERROR_RETURN_TYPE - Failed
  -- Performing Test HAVE_C_WERROR_RETURN_TYPE
  -- Performing Test HAVE_C_WERROR_RETURN_TYPE - Failed
  -- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR
  -- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR - Failed
  -- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR
  -- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR - Failed
  -- Performing Test HAVE_CXX_WERROR_ADDRESS
  -- Performing Test HAVE_CXX_WERROR_ADDRESS - Failed
  -- Performing Test HAVE_C_WERROR_ADDRESS
  -- Performing Test HAVE_C_WERROR_ADDRESS - Failed
  -- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT
  -- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT - Failed
  -- Performing Test HAVE_C_WERROR_SEQUENCE_POINT
  -- Performing Test HAVE_C_WERROR_SEQUENCE_POINT - Failed
  -- Performing Test HAVE_CXX_WFORMAT
  -- Performing Test HAVE_CXX_WFORMAT - Failed
  -- Performing Test HAVE_C_WFORMAT
  -- Performing Test HAVE_C_WFORMAT - Failed
  -- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY
  -- Performing Test HAVE_CXX_WERROR_FORMAT_SECURITY - Failed
  -- Performing Test HAVE_C_WERROR_FORMAT_SECURITY
  -- Performing Test HAVE_C_WERROR_FORMAT_SECURITY - Failed
  -- Performing Test HAVE_CXX_WMISSING_DECLARATIONS
  -- Performing Test HAVE_CXX_WMISSING_DECLARATIONS - Failed
  -- Performing Test HAVE_C_WMISSING_DECLARATIONS
  -- Performing Test HAVE_C_WMISSING_DECLARATIONS - Failed
  -- Performing Test HAVE_CXX_WMISSING_PROTOTYPES
  -- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed
  -- Performing Test HAVE_C_WMISSING_PROTOTYPES
  -- Performing Test HAVE_C_WMISSING_PROTOTYPES - Failed
  -- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES
  -- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES - Failed
  -- Performing Test HAVE_C_WSTRICT_PROTOTYPES
  -- Performing Test HAVE_C_WSTRICT_PROTOTYPES - Failed
  -- Performing Test HAVE_CXX_WUNDEF
  -- Performing Test HAVE_CXX_WUNDEF - Failed
  -- Performing Test HAVE_C_WUNDEF
  -- Performing Test HAVE_C_WUNDEF - Failed
  -- Performing Test HAVE_CXX_WINIT_SELF
  -- Performing Test HAVE_CXX_WINIT_SELF - Failed
  -- Performing Test HAVE_C_WINIT_SELF
  -- Performing Test HAVE_C_WINIT_SELF - Failed
  -- Performing Test HAVE_CXX_WPOINTER_ARITH
  -- Performing Test HAVE_CXX_WPOINTER_ARITH - Failed
  -- Performing Test HAVE_C_WPOINTER_ARITH
  -- Performing Test HAVE_C_WPOINTER_ARITH - Failed
  -- Performing Test HAVE_CXX_WSHADOW
  -- Performing Test HAVE_CXX_WSHADOW - Failed
  -- Performing Test HAVE_C_WSHADOW
  -- Performing Test HAVE_C_WSHADOW - Failed
  -- Performing Test HAVE_CXX_WSIGN_PROMO
  -- Performing Test HAVE_CXX_WSIGN_PROMO - Failed
  -- Performing Test HAVE_C_WSIGN_PROMO
  -- Performing Test HAVE_C_WSIGN_PROMO - Failed
  -- Performing Test HAVE_CXX_WUNINITIALIZED
  -- Performing Test HAVE_CXX_WUNINITIALIZED - Failed
  -- Performing Test HAVE_C_WUNINITIALIZED
  -- Performing Test HAVE_C_WUNINITIALIZED - Failed
  -- Performing Test HAVE_CXX_WINCONSISTENT_MISSING_OVERRIDE
  -- Performing Test HAVE_CXX_WINCONSISTENT_MISSING_OVERRIDE - Failed
  -- Performing Test HAVE_C_WINCONSISTENT_MISSING_OVERRIDE
  -- Performing Test HAVE_C_WINCONSISTENT_MISSING_OVERRIDE - Failed
  -- Performing Test HAVE_CXX_WNO_NARROWING
  -- Performing Test HAVE_CXX_WNO_NARROWING - Failed
  -- Performing Test HAVE_C_WNO_NARROWING
  -- Performing Test HAVE_C_WNO_NARROWING - Failed
  -- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR
  -- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR - Failed
  -- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR
  -- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR - Failed
  -- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
  -- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
  -- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
  -- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
  -- Performing Test HAVE_CXX_WNO_COMMENT
  -- Performing Test HAVE_CXX_WNO_COMMENT - Failed
  -- Performing Test HAVE_C_WNO_COMMENT
  -- Performing Test HAVE_C_WNO_COMMENT - Failed
  -- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION
  -- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION - Failed
  -- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION
  -- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION - Failed
  -- Performing Test HAVE_CXX_PTHREAD
  -- Performing Test HAVE_CXX_PTHREAD - Failed
  -- Performing Test HAVE_C_PTHREAD
  -- Performing Test HAVE_C_PTHREAD - Failed
  -- Performing Test HAVE_CXX_QUNUSED_ARGUMENTS
  -- Performing Test HAVE_CXX_QUNUSED_ARGUMENTS - Failed
  -- Performing Test HAVE_C_QUNUSED_ARGUMENTS
  -- Performing Test HAVE_C_QUNUSED_ARGUMENTS - Failed
  -- Performing Test HAVE_CXX_FFUNCTION_SECTIONS
  -- Performing Test HAVE_CXX_FFUNCTION_SECTIONS - Failed
  -- Performing Test HAVE_C_FFUNCTION_SECTIONS
  -- Performing Test HAVE_C_FFUNCTION_SECTIONS - Failed
  -- Performing Test HAVE_CXX_FDATA_SECTIONS
  -- Performing Test HAVE_CXX_FDATA_SECTIONS - Failed
  -- Performing Test HAVE_C_FDATA_SECTIONS
  -- Performing Test HAVE_C_FDATA_SECTIONS - Failed
  -- Performing Test HAVE_CPU_BASELINE_FLAGS
  -- Performing Test HAVE_CPU_BASELINE_FLAGS - Failed
  CMake Error at cmake/OpenCVCompilerOptimizations.cmake:524 (message):
    Compiler doesn't support baseline optimization flags:
  Call Stack (most recent call first):
    cmake/OpenCVCompilerOptions.cmake:270 (ocv_compiler_optimization_options)
    CMakeLists.txt:682 (include)
  
  
  -- Configuring incomplete, errors occurred!
  See also "C:/opencv/build_wasm/CMakeFiles/CMakeOutput.log".
  See also "C:/opencv/build_wasm/CMakeFiles/CMakeError.log".
  Traceback (most recent call last):
    File "platforms\js\build_js.py", line 224, in &lt;module&gt;
      builder.config()
    File "platforms\js\build_js.py", line 164, in config
      execute(cmd)
    File "platforms\js\build_js.py", line 23, in execute
      raise Fail("Child returned: %s" % retcode)
  __main__.Fail: Child returned: 1
  </code></pre>
  
  <p>even though I followed <a href="https://github.com/Web-Sight/WebSight/issues/18" rel="nofollow noreferrer">this post</a> and used python2 with opencl, binaryen, cmake, emscripten_dir provided</p>
  
  <p>I also tried direct cmake command with options <a href="http://answers.opencv.org/question/192758/compile-error-when-compiling-for-windows-341-dev/" rel="nofollow noreferrer">from here</a> like:</p>
  
  <pre><code>cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE='d:/microSoft/emsdk/emscripten/1.38.21/cmake/Modules/Platform/Emscripten.cmake' -DCPU_BASELINE='' -DCPU_DISPATCH='' -DCV_TRACE=OFF -DBUILD_SHARED_LIBS=OFF -DWITH_1394=OFF -DWITH_ADE=OFF -DWITH_VTK=OFF -DWITH_EIGEN=OFF -DWITH_FFMPEG=OFF -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_GTK_2_X=OFF -DWITH_IPP=OFF -DWITH_JASPER=OFF -DWITH_JPEG=OFF -DWITH_WEBP=OFF -DWITH_OPENEXR=OFF -DWITH_OPENGL=OFF -DWITH_OPENVX=OFF -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DWITH_PNG=OFF -DWITH_TBB=OFF -DWITH_PTHREADS_PF=OFF -DWITH_TIFF=OFF -DWITH_V4L=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_GPHOTO2=OFF -DWITH_LAPACK=OFF -DWITH_ITT=OFF -DBUILD_ZLIB=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_calib3d=ON -DBUILD_opencv_dnn=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_flann=ON -DBUILD_opencv_gapi=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_photo=ON -DBUILD_opencv_imgcodecs=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_videoio=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_highgui=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_js=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON_EXECUTABLE=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe -DPYTHON_INCLUDE_DIRS=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/include -DPYTHON_LIBRARY=d:/microSoft/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/libs/libpython27.a -S . -B build_js
  </code></pre>
  
  <p>This finished but mingw32-make failed</p>
  
  <p>If you find anything odd in my setup or the command I try please let me know. Any suggestion is welcome.
  Thanks a lot.</p>