omkar-mohanty / opencv-wasm

6 stars 0 forks source link

I try to compile wasi , show some err #1

Open lchjczw opened 6 months ago

lchjczw commented 6 months ago

cargo build --target=wasm32-wasi --release

Compiling opencv-wasm v0.1.0 (/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm) The following warnings were emitted during compilation:

warning: opencv-wasm@0.1.0: In file included from /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/sources/opencv-wasm/src/lib.rs.cc:1: warning: opencv-wasm@0.1.0: In file included from /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/crate/opencv-wasm/include/imgcodecs.hpp:5: warning: opencv-wasm@0.1.0: In file included from /opt/homebrew/include/opencv4/opencv2/imgcodecs.hpp:46: warning: opencv-wasm@0.1.0: In file included from /opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core.hpp:3392: warning: opencv-wasm@0.1.0: /opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core/utility.hpp:718:14: error: no type named 'recursive_mutex' in namespace 'std' warning: opencv-wasm@0.1.0: 718 | typedef std::recursive_mutex Mutex; warning: opencv-wasm@0.1.0: | ~^ warning: opencv-wasm@0.1.0: /opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core/utility.hpp:719:14: error: no template named 'lock_guard' in namespace 'std' warning: opencv-wasm@0.1.0: 719 | typedef std::lock_guard AutoLock; warning: opencv-wasm@0.1.0: | ~^ warning: opencv-wasm@0.1.0: 2 errors generated.

error: failed to run custom build command for opencv-wasm v0.1.0 (/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm)

Caused by: process didn't exit successfully: /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/release/build/opencv-wasm-b8b2072f1077a9ae/build-script-build (exit status: 1) --- stdout cargo:rustc-link-search=lib cargo:CXXBRIDGE_PREFIX=opencv-wasm cargo:CXXBRIDGE_DIR0=/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/include cargo:CXXBRIDGE_DIR1=/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/crate cargo:rustc-link-lib=static=opencv_highgui cargo:rustc-link-lib=static=opencv_imgproc cargo:rustc-link-lib=static=opencv_imgcodecs cargo:rustc-link-lib=static=opencv_core cargo:rustc-link-lib=static=c++ cargo:rustc-link-lib=static=c++abi cargo:rustc-link-lib=static=webp cargo:rustc-link-lib=static=openjp2 TARGET = Some("wasm32-wasi") OPT_LEVEL = Some("3") HOST = Some("aarch64-apple-darwin") cargo:rerun-if-env-changed=CXX_wasm32-wasi CXX_wasm32-wasi = None cargo:rerun-if-env-changed=CXX_wasm32_wasi CXX_wasm32_wasi = Some("/opt/wasi-sdk-22.0/bin/clang++ --sysroot=/opt/wasi-sdk-22.0/share/wasi-sysroot --target=wasm32-wasi") cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") cargo:rerun-if-env-changed=CXXFLAGS_wasm32-wasi CXXFLAGS_wasm32-wasi = None cargo:rerun-if-env-changed=CXXFLAGS_wasm32_wasi CXXFLAGS_wasm32_wasi = None cargo:rerun-if-env-changed=TARGET_CXXFLAGS TARGET_CXXFLAGS = None cargo:rerun-if-env-changed=CXXFLAGS CXXFLAGS = None cargo:warning=In file included from /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/sources/opencv-wasm/src/lib.rs.cc:1: cargo:warning=In file included from /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/crate/opencv-wasm/include/imgcodecs.hpp:5: cargo:warning=In file included from /opt/homebrew/include/opencv4/opencv2/imgcodecs.hpp:46: cargo:warning=In file included from /opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core.hpp:3392: cargo:warning=/opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core/utility.hpp:718:14: error: no type named 'recursive_mutex' in namespace 'std' cargo:warning= 718 | typedef std::recursive_mutex Mutex; cargo:warning= | ~^ cargo:warning=/opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4/opencv2/core/utility.hpp:719:14: error: no template named 'lock_guard' in namespace 'std' cargo:warning= 719 | typedef std::lock_guard AutoLock; cargo:warning= | ~^ cargo:warning=2 errors generated.

--- stderr

CXX include path: /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/include /Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/crate

error occurred: Command "/opt/wasi-sdk-22.0/bin/clang++" "--sysroot=/opt/wasi-sdk-22.0/share/wasi-sysroot" "--target=wasm32-wasi" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-I" "/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/include" "-I" "/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/crate" "-I" "/usr/local/include" "-I" "/opt/homebrew/include" "-I" "/opt/homebrew/Cellar/opencv/4.9.0_8/include" "-I" "/opt/homebrew/Cellar/opencv/4.9.0_8/include/opencv4" "-Wall" "-Wextra" "-o" "/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/d859a080b9db372b-lib.rs.o" "-c" "/Users/lchjczw/work/rust/video/httpvideo/real-time_webcam_streaming_server/opencv-wasm/target/wasm32-wasi/release/build/opencv-wasm-b694b60037c198f4/out/cxxbridge/sources/opencv-wasm/src/lib.rs.cc" with args clang++ did not execute successfully (status code exit status: 1).

lchjczw commented 6 months ago

From the error messages, the issue occurs when trying to compile OpenCV into WebAssembly. The errors point out that std::recursive_mutex and std::lock_guard are not found in the specified namespace. This is because these synchronization primitives (such as mutexes) from the C++ standard library are not by default available for WebAssembly targets, as the WebAssembly environment (especially in browser contexts) itself does not support threads and synchronization primitives. Despite the recent incremental support for multi-threading features in WebAssembly, this support isn't enabled by default in many environments.