Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WASM target #124

Open
Horki opened this issue May 4, 2020 · 24 comments
Open

Add support for WASM target #124

Horki opened this issue May 4, 2020 · 24 comments

Comments

@Horki
Copy link

Horki commented May 4, 2020

Before reporting an issue please first check the
troubleshooting guide. If
the issue you're encountering is not solved thereby please state the following in your bugreport:

  1. Operating system
    5.6.10-arch1-1 GNU/Linux
  2. The way you installed OpenCV: package, official binary distribution, manual compilation, etc.
    via "packer" manager
  3. OpenCV version
    4.3.0
  4. Attach the full output of the following command from your project directory:
    RUST_BACKTRACE=full cargo build -vv 

Version
rustc 1.43.0 (4fb7144ed 2020-04-20)

Target
wasm32-unknown-unknown

CLI
cargo +stable build --release --target=wasm32-unknown-unknown

   Compiling num-traits v0.2.11
   Compiling opencv v0.34.0
error: failed to run custom build command for `opencv v0.34.0`

Caused by:
  process didn't exit successfully: `/home/horky/Documents/WorkspaceRust/cvwasm/target/release/build/opencv-e2dc348207d786b2/build-script-build` (exit code: 1)
--- stderr
=== Environment configuration:
===   OPENCV_HEADER_DIR = None
===   OPENCV_PACKAGE_NAME = None
===   OPENCV_PKGCONFIG_NAME = None
===   OPENCV_LINK_LIBS = None
===   OPENCV_LINK_PATHS = None
===   OPENCV_INCLUDE_PATHS = None
===   PKG_CONFIG_PATH = None
===   VCPKG_ROOT = None
=== Setting up OpenCV library from pkg_config
Error: "Package opencv4 is not found, caused by: Cross compilation detected. Use PKG_CONFIG_ALLOW_CROSS=1 to override"

warning: build failed, waiting for other jobs to finish...
error: build failed

I didn't succeed to find a way of working OpenCV (rust+wasm) example on internet, is there a way to build it properly?

PS. Trivia I would like to rewrite my simple app from C++ intro rust

@twistedfall
Copy link
Owner

Not that I have tested it in any way, but did you try doing what it suggested?

Use PKG_CONFIG_ALLOW_CROSS=1 to override

@Horki
Copy link
Author

Horki commented May 4, 2020

Yes, I have but unsuccessfully. ( I also posted in the user group, in January)

log dump

   Compiling num v0.2.1
   Compiling opencv v0.34.0
error: failed to run custom build command for `opencv v0.34.0`

Caused by:
  process didn't exit successfully: `/home/horky/Documents/WorkspaceRust/cvwasm/target/release/build/opencv-e2dc348207d786b2/build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-env-changed=OPENCV_HEADER_DIR
cargo:rerun-if-env-changed=OPENCV_PACKAGE_NAME
cargo:rerun-if-env-changed=OPENCV_PKGCONFIG_NAME
cargo:rerun-if-env-changed=OPENCV_LINK_LIBS
cargo:rerun-if-env-changed=OPENCV_LINK_PATHS
cargo:rerun-if-env-changed=OPENCV_INCLUDE_PATHS
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=VCPKG_ROOT
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/dnn.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/videoio.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/core.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/manual-dnn.cpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/face.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/manual-core.cpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/aruco.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/ocvrs_resolve_types.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/manual-features2d.cpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/hdf.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/calib3d.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/ccalib.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/bioinspired.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/sfm.hpp
cargo:rerun-if-changed=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/imgproc.hpp
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/aruco.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/aruco.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/calib3d.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/calib3d.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/core.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/core.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/ccalib.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/ccalib.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/alphamat.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/alphamat.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bgsegm.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bgsegm.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bioinspired.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bioinspired.cpp"
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/manual-core.o" "-c" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/manual-core.cpp"
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/aruco.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/aruco.hpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
running: "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/cvv.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/cvv.cpp"
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/alphamat.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/calib3d.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/calib3d.hpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bgsegm.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/manual-core.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/core.hpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/bioinspired.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/bioinspired.hpp:3:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/ccalib.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/ccalib.hpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/core.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/core.hpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/cvv.cpp:1:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp/common.hpp:2:
cargo:warning=In file included from /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core.hpp:52:
cargo:warning=/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4/opencv2/core/cvdef.h:171:10: fatal error: 'limits' file not found
cargo:warning=#include <limits>
cargo:warning=         ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1

--- stderr
=== Environment configuration:
===   OPENCV_HEADER_DIR = None
===   OPENCV_PACKAGE_NAME = None
===   OPENCV_PKGCONFIG_NAME = None
===   OPENCV_LINK_LIBS = None
===   OPENCV_LINK_PATHS = None
===   OPENCV_INCLUDE_PATHS = None
===   PKG_CONFIG_PATH = None
===   VCPKG_ROOT = None
=== Setting up OpenCV library from pkg_config
=== OpenCV library configuration: Library {
    pkg_name: "opencv4",
    include_paths: [
        "/usr/include/opencv4",
    ],
    version: "4.3.0",
    cargo_metadata: [
        "cargo:rustc-link-search=native=/usr/lib",
        "cargo:rustc-link-lib=opencv_gapi",
        "cargo:rustc-link-lib=opencv_stitching",
        "cargo:rustc-link-lib=opencv_alphamat",
        "cargo:rustc-link-lib=opencv_aruco",
        "cargo:rustc-link-lib=opencv_bgsegm",
        "cargo:rustc-link-lib=opencv_bioinspired",
        "cargo:rustc-link-lib=opencv_ccalib",
        "cargo:rustc-link-lib=opencv_cvv",
        "cargo:rustc-link-lib=opencv_dnn_objdetect",
        "cargo:rustc-link-lib=opencv_dnn_superres",
        "cargo:rustc-link-lib=opencv_dpm",
        "cargo:rustc-link-lib=opencv_highgui",
        "cargo:rustc-link-lib=opencv_face",
        "cargo:rustc-link-lib=opencv_freetype",
        "cargo:rustc-link-lib=opencv_fuzzy",
        "cargo:rustc-link-lib=opencv_hdf",
        "cargo:rustc-link-lib=opencv_hfs",
        "cargo:rustc-link-lib=opencv_img_hash",
        "cargo:rustc-link-lib=opencv_intensity_transform",
        "cargo:rustc-link-lib=opencv_line_descriptor",
        "cargo:rustc-link-lib=opencv_quality",
        "cargo:rustc-link-lib=opencv_rapid",
        "cargo:rustc-link-lib=opencv_reg",
        "cargo:rustc-link-lib=opencv_rgbd",
        "cargo:rustc-link-lib=opencv_saliency",
        "cargo:rustc-link-lib=opencv_stereo",
        "cargo:rustc-link-lib=opencv_structured_light",
        "cargo:rustc-link-lib=opencv_phase_unwrapping",
        "cargo:rustc-link-lib=opencv_superres",
        "cargo:rustc-link-lib=opencv_optflow",
        "cargo:rustc-link-lib=opencv_surface_matching",
        "cargo:rustc-link-lib=opencv_tracking",
        "cargo:rustc-link-lib=opencv_datasets",
        "cargo:rustc-link-lib=opencv_text",
        "cargo:rustc-link-lib=opencv_dnn",
        "cargo:rustc-link-lib=opencv_plot",
        "cargo:rustc-link-lib=opencv_videostab",
        "cargo:rustc-link-lib=opencv_videoio",
        "cargo:rustc-link-lib=opencv_viz",
        "cargo:rustc-link-lib=opencv_xfeatures2d",
        "cargo:rustc-link-lib=opencv_shape",
        "cargo:rustc-link-lib=opencv_ml",
        "cargo:rustc-link-lib=opencv_ximgproc",
        "cargo:rustc-link-lib=opencv_video",
        "cargo:rustc-link-lib=opencv_xobjdetect",
        "cargo:rustc-link-lib=opencv_objdetect",
        "cargo:rustc-link-lib=opencv_calib3d",
        "cargo:rustc-link-lib=opencv_imgcodecs",
        "cargo:rustc-link-lib=opencv_features2d",
        "cargo:rustc-link-lib=opencv_flann",
        "cargo:rustc-link-lib=opencv_xphoto",
        "cargo:rustc-link-lib=opencv_photo",
        "cargo:rustc-link-lib=opencv_imgproc",
        "cargo:rustc-link-lib=opencv_core",
    ],
}
=== Found OpenCV library version: 4.3.0 in headers located at: /home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4


error occurred: Command "sccache" "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/src_cpp" "-I" "/home/horky/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.34.0/headers/4" "-I" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out" "-I" "." "-Wall" "-Wextra" "-std=c++11" "-o" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/alphamat.o" "-c" "/home/horky/Documents/WorkspaceRust/cvwasm/target/wasm32-unknown-unknown/release/build/opencv-18a6d2821fe7f5f3/out/alphamat.cpp" with args "clang" did not execute successfully (status code exit code: 1).

@twistedfall
Copy link
Owner

I see. Well, the current build process is targeted at using OpenCV as a native shared library which is not supported in wasm environment obviously. I do have plans to explore this direction though and any help is greatly appreciated!

@Horki
Copy link
Author

Horki commented May 4, 2020

I have a simple example of how to build OpenCV into Emscripten target, but still not sure how to "glue" it properly with "rustc".

https://github.com/Horki/lanelines_wasm_emscripten/blob/master/BUILD.md

@kalwalt
Copy link

kalwalt commented Jan 22, 2021

Hi @Horki @twistedfall I am also insterested in this topic. I have a bit of experience with Emscripten, and yes probably is required to link the OpenCV static libs compiled with Emscripten in the final stage of the project. I would try to dig into this, but i feel as an absolute beginner (almost) with Rust. 😢

@twistedfall
Copy link
Owner

Hi, well, this task is up for grabs if you feel like it. I've done a preliminary investigation and it's not an easy deal. You would need to have some javascript glue to link wasm from opencv crate with wasm from OpenCV lib. Then there is also question of mapping the data structs between them. It's a good investigative task, but not something you would do in a week.

@xyz27900
Copy link

@twistedfall does problem solved? I tried to build my app with wasm-pack and have similar errors

@twistedfall
Copy link
Owner

Nope, no real work has been done in that direction yet as far as I know.

@kalwalt
Copy link

kalwalt commented Mar 15, 2021

Hi, well, this task is up for grabs if you feel like it. I've done a preliminary investigation and it's not an easy deal. You would need to have some javascript glue to link wasm from opencv crate with wasm from OpenCV lib. Then there is also question of mapping the data structs between them. It's a good investigative task, but not something you would do in a week.

Hi @twistedfall back on this. Have you a reference example for this? Not with opencv-rust but another project that used the approach you explained. Thank you.

@twistedfall
Copy link
Owner

Not really, I don’t think something like this has ever been done to be honest.

@twistedfall
Copy link
Owner

Alternatively it may be possible to build OpenCV as static wasm and link it directly to the Rust wasm binary. As far as I know this will imply going around the standard OpenCV wasm build procedure and writing your own build script.

@kalwalt
Copy link

kalwalt commented Mar 16, 2021

Alternatively it may be possible to build OpenCV as static wasm and link it directly to the Rust wasm binary. As far as I know this will imply going around the standard OpenCV wasm build procedure and writing your own build script.

i did already for wasm-ar project by @EdwardLu2018 see this build script https://github.com/webarkit/opencv-em it build the opencv static libs with WASM emscripten. But how can i link the static libs in Rust?

@twistedfall
Copy link
Owner

That's a good start, I didn't realize it existed! It might be way simpler to go this way. For now I'm not sure how do you statically link another wasm library. There are some hits on google like https://users.rust-lang.org/t/how-to-static-link-c-lib-to-wasm/36558 so it seems to be doable.

@kalwalt
Copy link

kalwalt commented Mar 16, 2021

That article is a good example i think, I will try a similar approach. Thank you @twistedfall !

@Horki Horki closed this as completed Mar 17, 2021
@twistedfall
Copy link
Owner

I would prefer to keep it open as a todo item if you don’t mind

@twistedfall twistedfall reopened this Mar 17, 2021
yokra9 added a commit to yokra9/wasm-image-resizer that referenced this issue Aug 2, 2021
yokra9 added a commit to yokra9/wasm-image-resizer that referenced this issue Aug 2, 2021
@h4x3rotab
Copy link

Would be nice to have wasm target added

@ChillSheep
Copy link

Is there any work being done for this? It seems to compile fine but the linker fails

@twistedfall
Copy link
Owner

Not at the moment unfortunately. Linking is the main problem indeed.

@mattangus
Copy link

mattangus commented Aug 10, 2024

I was able to successfully build this repo. It was for the wasm32-unknown-emscripten target rather than wasm32-unknown-unknown.

Following the build instructions for opencv for wasm with the --wasm flag (i.e. emcmake python3 platforms/js/build_js.py build_js --build_wasm). This builds a bunch of static archives. So you just need to run make install from the build folder, and point opencv-rust to the install location. Unfortunately the install prefix is hard coded in platforms/js/build_js.py.

# check the install dir for the list of libs built
export OPENCV_LINK_LIBS=opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_imgproc,opencv_objdetect,opencv_photo,opencv_video
export OPENCV_LINK_PATHS=/path/to/install/lib/
export OPENCV_INCLUDE_PATHS=/path/to/install/include/opencv4/
export OPENCV_LINKAGE=static

cargo build --target=wasm32-unknown-emscripten

You can also set these values in .cargo/config.toml.

I don't know if its actually usable though, since emscripten doesn't work with wasm-bindgen

@twistedfall
Copy link
Owner

twistedfall commented Aug 12, 2024

That's great news! I will try to reproduce it, thank you for sharing!

I don't know if its actually usable though, since emscripten doesn't work with wasm-bindgen

Still, it's a step in the right direction

@CeNiEi
Copy link

CeNiEi commented Aug 12, 2024

Hello, @mattangus ,Thanks for sharing your method. I tried using it, but I see the following get the warnings:

 note: wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'algorithm.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'alloc.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'arithm.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'arithm.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'array.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'async.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'batch_distance.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'bindings_utils.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'buffer_area.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'channels.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'check.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'command_line_parser.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'conjugate_gradient.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert_c.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert_scale.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'copy.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'count_non_zero.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_gpu_mat.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_gpu_mat_nd.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_host_mem.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_info.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_stream.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'datastructs.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'directx.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'downhill_simplex.cpp.o' is neither Wasm object file nor LLVM bitcode
          ...

and then the linking fails with

 emcc: error: '/Users/tushar/Aftershoot/emsdk/upstream/bin/wasm-ld -o /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.wasm /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.temp.7907a7cd61e9fa75-cgu.0.rcgu.o /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.9qr5wamp2zed2w4tk6teolorc.rcgu.o -L/Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps -L/Users/tushar/Meditations/Exps/temp/target/release/deps -L/Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/build/opencv-33eb669076e3c94c/out -L/Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib -L/Users/tushar/Aftershoot/backend/lib/macos/arm64/libjpeg/lib -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/libopencv-b31e8443eece564d.rlib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/liblibc-8648be1f97d4a9d9.rlib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/libnum_traits-669bc3b55d805a23.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-078a2440946b4ad9.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_unwind-38df63a19dbda819.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_demangle-613f369fbf1858bc.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_detect-66829d196d7e3f32.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libhashbrown-31c79f03125d17f2.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_alloc-95a3ab51dbc79ccc.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libminiz_oxide-bc3bd3e2b31ed919.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libadler-b7250bbf9f70ffb3.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-5e22616f1b445a53.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcfg_if-5601884a4b7e82c7.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-bbff3e626f351ebb.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-0830855ff540bd35.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_core-392cd8b7d678e020.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-0ee71266a6bac8a1.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-5cee2ca66d5fec8d.rlib /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_imgcodecs.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_imgproc.a -littnotify /Users/tushar/Aftershoot/backend/lib/macos/arm64/libjpeg/lib/libturbojpeg.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/liblibtiff.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libtegra_hal.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libzlib.a -lc -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained -L/Users/tushar/Aftershoot/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL-getprocaddr -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/qr/w92rrf2x5pn_ny17y7kljt300000gn/T/tmpz6u0sdy4libemscripten_js_symbols.so --strip-debug --export=ocvrs_create_byte_string --export=ocvrs_create_string --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__cxa_is_pointer_type --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=setThrew --export=__cxa_free_exception --export=__wasm_call_ctors --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --table-base=1 --global-base=1024' failed (returned 1)

I used the following command to run the script

emcmake python3 platforms/js/build_js.py out/build --build_wasm --cmake_option="-DOPENCV_EXTRA_MODULES_PATH=/Users/tushar/Aftershoot/opencv_contrib/modules" 

I also checked what these object files are:

algorithm.cpp.o:                   WebAssembly (wasm) binary module version 0x1 (MVP)
alloc.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
arithm.cpp.o:                      WebAssembly (wasm) binary module version 0x1 (MVP)
arithm.dispatch.cpp.o:             WebAssembly (wasm) binary module version 0x1 (MVP)
array.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
async.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
batch_distance.cpp.o:              WebAssembly (wasm) binary module version 0x1 (MVP)
bindings_utils.cpp.o:              WebAssembly (wasm) binary module version 0x1 (MVP)
buffer_area.cpp.o:                 WebAssembly (wasm) binary module version 0x1 (MVP)
channels.cpp.o:                    WebAssembly (wasm) binary module version 0x1 (MVP)
check.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)

These seem to be wasm modules.. But then why the linker is complaining..

Any help will be appreciated.

@mattangus
Copy link

@CeNiEi That seems to work for me. Check the build logs (cargo build -vv --target=wasm32-unknown-emscripten). There should be something like this:

[opencv 0.92.2] === Detected probe priority boost based on environment vars: pkg_config: false, cmake: false, vcpkg: false
[opencv 0.92.2] === Probing the OpenCV library in the following order: environment, pkg_config, cmake, vcpkg_cmake, vcpkg
[opencv 0.92.2] === Configuring OpenCV library from the environment:
[opencv 0.92.2] ===   include_paths: /path/to/installed/include
[opencv 0.92.2] ===   link_paths: /path/to/installed/lib
[opencv 0.92.2] ===   link_libs: opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_imgproc,opencv_objdetect,opencv_photo,opencv_video

@kalwalt
Copy link

kalwalt commented Aug 18, 2024

Hello, @mattangus ,Thanks for sharing your method. I tried using it, but I see the following get the warnings:

 note: wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'algorithm.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'alloc.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'arithm.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'arithm.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'array.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'async.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'batch_distance.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'bindings_utils.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'buffer_area.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'channels.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'check.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'command_line_parser.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'conjugate_gradient.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert_c.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'convert_scale.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'copy.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'count_non_zero.dispatch.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_gpu_mat.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_gpu_mat_nd.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_host_mem.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_info.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'cuda_stream.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'datastructs.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'directx.cpp.o' is neither Wasm object file nor LLVM bitcode
          wasm-ld: warning: /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a: archive member 'downhill_simplex.cpp.o' is neither Wasm object file nor LLVM bitcode
          ...

and then the linking fails with

 emcc: error: '/Users/tushar/Aftershoot/emsdk/upstream/bin/wasm-ld -o /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.wasm /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.temp.7907a7cd61e9fa75-cgu.0.rcgu.o /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/temp.9qr5wamp2zed2w4tk6teolorc.rcgu.o -L/Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps -L/Users/tushar/Meditations/Exps/temp/target/release/deps -L/Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/build/opencv-33eb669076e3c94c/out -L/Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib -L/Users/tushar/Aftershoot/backend/lib/macos/arm64/libjpeg/lib -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/libopencv-b31e8443eece564d.rlib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/liblibc-8648be1f97d4a9d9.rlib /Users/tushar/Meditations/Exps/temp/target/wasm32-unknown-emscripten/release/deps/libnum_traits-669bc3b55d805a23.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-078a2440946b4ad9.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_unwind-38df63a19dbda819.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_demangle-613f369fbf1858bc.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_detect-66829d196d7e3f32.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libhashbrown-31c79f03125d17f2.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_alloc-95a3ab51dbc79ccc.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libminiz_oxide-bc3bd3e2b31ed919.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libadler-b7250bbf9f70ffb3.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-5e22616f1b445a53.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcfg_if-5601884a4b7e82c7.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-bbff3e626f351ebb.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-0830855ff540bd35.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_core-392cd8b7d678e020.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-0ee71266a6bac8a1.rlib /Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-5cee2ca66d5fec8d.rlib /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_core.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_imgcodecs.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libopencv_imgproc.a -littnotify /Users/tushar/Aftershoot/backend/lib/macos/arm64/libjpeg/lib/libturbojpeg.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/liblibtiff.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libtegra_hal.a /Users/tushar/Aftershoot/backend/lib/macos/arm64/opencv/lib/libzlib.a -lc -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib -L/Users/tushar/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained -L/Users/tushar/Aftershoot/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL-getprocaddr -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/qr/w92rrf2x5pn_ny17y7kljt300000gn/T/tmpz6u0sdy4libemscripten_js_symbols.so --strip-debug --export=ocvrs_create_byte_string --export=ocvrs_create_string --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__cxa_is_pointer_type --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=setThrew --export=__cxa_free_exception --export=__wasm_call_ctors --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --table-base=1 --global-base=1024' failed (returned 1)

I used the following command to run the script

emcmake python3 platforms/js/build_js.py out/build --build_wasm --cmake_option="-DOPENCV_EXTRA_MODULES_PATH=/Users/tushar/Aftershoot/opencv_contrib/modules" 

I also checked what these object files are:

algorithm.cpp.o:                   WebAssembly (wasm) binary module version 0x1 (MVP)
alloc.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
arithm.cpp.o:                      WebAssembly (wasm) binary module version 0x1 (MVP)
arithm.dispatch.cpp.o:             WebAssembly (wasm) binary module version 0x1 (MVP)
array.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
async.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)
batch_distance.cpp.o:              WebAssembly (wasm) binary module version 0x1 (MVP)
bindings_utils.cpp.o:              WebAssembly (wasm) binary module version 0x1 (MVP)
buffer_area.cpp.o:                 WebAssembly (wasm) binary module version 0x1 (MVP)
channels.cpp.o:                    WebAssembly (wasm) binary module version 0x1 (MVP)
check.cpp.o:                       WebAssembly (wasm) binary module version 0x1 (MVP)

These seem to be wasm modules.. But then why the linker is complaining..

Any help will be appreciated.

@CeNiEi Probably you should avoid to build opencv with extra modules as you can see from @mattangus instructions there are only a set of limited opencv libs

@CeNiEi
Copy link

CeNiEi commented Aug 19, 2024

@mattangus @kalwalt
But the issue is that I want to use the opencv_contrib modules. And the original opencv_js script does in fact support building with contrib modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants