-
Notifications
You must be signed in to change notification settings - Fork 192
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
OpenCV compilation errors #490
Comments
If you just want to use the SDK then I suggest you down the prebuilt binaries from https://github.com/WebAssembly/wasi-sdk/releases rather than trying to build it yourself from source. |
Aight, I did just that:
and:
Same error: Details
|
The clang that cmake is using is still the one you built yourself ( |
Thanks, that fixed it, but I did a
I'm not at all familiar with CMake, but where would the suggested |
The |
It seems like I can't put any flags when doing
And even if I put the -D flag to recompile the thing with
And do the linker flags go in the same compile command? |
|
Thanks, so that's solved, but here's another error:
It couldn't have been an OpenCV error could it? It builds just fine otherwise. |
@Brennanzuz The error you are having is beacause Important Note: I couldn't build the repository with Important Note: you have to comment the following lines inside opencv-4.10.0/modules/core/src/parallel.cpp WASI_SDK_PATH=/home/gnery/wasi-sdk-24.0-x86_64-linux
rm -rf ./build
mkdir -p build && cd build
cmake \
-DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk-pthread.cmake \
-DCMAKE_INSTALL_PREFIX=/home/gnery/Desktop/Projeto_pesquisa/opencv-wasm-rust/install \
-DOPENCV_EXTRA_MODULES_PATH=/home/gnery/Desktop/Projeto_pesquisa/opencv-wasm-rust/opencv_contrib-4.10.0/modules \
-DENABLE_PIC=FALSE \
-DCMAKE_BUILD_TYPE=Release \
-DCPU_BASELINE='' \
-DCPU_DISPATCH='' \
-DCV_TRACE=ON \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_1394=ON \
-DWITH_ADE=ON \
-DWITH_VTK=OFF \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=ON \
-DWITH_GTK=OFF \
-DWITH_GTK_2_X=OFF \
-DWITH_IPP=OFF \
-DWITH_JASPER=ON \
-DWITH_JPEG=ON \
-DWITH_WEBP=OFF \
-DWITH_OPENEXR=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENVX=ON \
-DWITH_OPENNI=ON \
-DWITH_OPENNI2=ON \
-DWITH_PNG=ON \
-DWITH_TBB=ON \
-DWITH_OPENMP=ON \
-DWITH_PTHREADS_PF=ON \
-DWITH_TIFF=ON \
-DWITH_V4L=OFF \
-DWITH_OPENCL=ON \
-DWITH_OPENCL_SVM=ON \
-DWITH_OPENCLAMDFFT=ON \
-DWITH_OPENCLAMDBLAS=ON \
-DWITH_GPHOTO2=OFF \
-DWITH_LAPACK=ON \
-DWITH_ITT=ON \
-DWITH_QUIRC=ON \
-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=ON \
-DBUILD_opencv_ml=ON \
-DBUILD_opencv_photo=ON \
-DBUILD_opencv_imgcodecs=OFF \
-DBUILD_opencv_shape=ON \
-DBUILD_opencv_videoio=ON \
-DBUILD_opencv_videostab=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_superres=ON \
-DBUILD_opencv_stitching=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_js=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DWITH_OPENJPEG=OFF \
../opencv-4.10.0
make -j16 EDIT WASI_SDK_PATH=/home/gnery/wasi-sdk-24.0-x86_64-linux
rm -rf ./build
mkdir -p build && cd build
cmake \
-DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk-pthread.cmake \
-DCMAKE_INSTALL_PREFIX=/home/gnery/Desktop/Projeto_pesquisa/opencv-wasm-rust/install \
-DOPENCV_EXTRA_MODULES_PATH=/home/gnery/Desktop/Projeto_pesquisa/opencv-wasm-rust/opencv_contrib-4.10.0/modules \
-DENABLE_PIC=FALSE \
-DCMAKE_BUILD_TYPE=Release \
-DCPU_BASELINE='' \
-DCPU_DISPATCH='' \
-DCV_TRACE=ON \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_1394=ON \
-DWITH_ADE=ON \
-DWITH_VTK=OFF \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=ON \
-DWITH_GTK=OFF \
-DWITH_GTK_2_X=OFF \
-DWITH_IPP=OFF \
-DWITH_JASPER=ON \
-DWITH_JPEG=ON \
-DWITH_WEBP=OFF \
-DWITH_OPENEXR=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENVX=ON \
-DWITH_OPENNI=ON \
-DWITH_OPENNI2=ON \
-DWITH_PNG=ON \
-DWITH_TBB=ON \
-DWITH_OPENMP=ON \
-DWITH_PTHREADS_PF=ON \
-DWITH_TIFF=ON \
-DWITH_V4L=OFF \
-DWITH_OPENCL=ON \
-DWITH_OPENCL_SVM=ON \
-DWITH_OPENCLAMDFFT=ON \
-DWITH_OPENCLAMDBLAS=ON \
-DWITH_GPHOTO2=OFF \
-DWITH_LAPACK=ON \
-DWITH_ITT=ON \
-DWITH_QUIRC=ON \
-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=ON \
-DBUILD_opencv_ml=ON \
-DBUILD_opencv_photo=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_shape=ON \
-DBUILD_opencv_videoio=ON \
-DBUILD_opencv_videostab=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_superres=ON \
-DBUILD_opencv_stitching=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_js=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PACKAGE=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DWITH_OPENJPEG=ON \
-DCMAKE_C_FLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -mllvm -wasm-enable-sjlj" \
-DCMAKE_CXX_FLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -mllvm -wasm-enable-sjlj" \
-DCMAKE_EXE_LINKER_FLAGS="-mllvm -wasm-enable-sjlj -lwasi-emulated-process-clocks -lwasi-emulated-signal" \
../opencv-4.10.0
make -j16 |
Thank you for checking it out. May I ask where did you get this |
this is just a simple directory inside my Desktop folder |
Oh yup, okay cool it builds, but what am I supposed to get to know that it worked? |
It does not work. Because, wasi sdk does not support exceptions. So you will get an linking error saying that exceptions are not defined |
@Brennanzuz I managed to build and run opencv with wasi target. As soon as possible I will share a repo showing how to do this |
@ggnery I wonder what language you used to call opencv funcs ;-) My bet is Rust, but who knows? |
Interesting enough, I have compiled opencv on Intel Mac following instructions from this topic. But have no idea how to call functions from my Rust app and compile it to wasm component compatible with Wasmcloud |
Sry, I cant publish this repo due to some licesense problemns. But here is a Idea of how to run compiled code 1)Once you have all opencv static libraries made on previous step, make a CMakeLists.txt importing those like this: cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME "test")
project(${PROJECT_NAME})
# Basic Config
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
#Some usefull flags
set(CMAKE_C_FLAGS "\
-Wl,--initial-memory=4194304000 \
-Wl,--shared-memory \
-mbulk-memory \
-mmutable-globals \
-msimd128 \
-matomics \
-Wl,--allow-undefined \
-Wl,--no-entry \
")
set(CMAKE_CXX_FLAGS "\
-Wl,--initial-memory=4194304000 \
-Wl,--shared-memory \
-mbulk-memory \
-mmutable-globals \
-msimd128 \
-matomics \
-Wl,--allow-undefined \
-Wl,--no-entry \
")
#Very importat because if not set the memory is turned into import by default
set(CMAKE_EXE_LINKER_FLAGS "")
# OPENCV config
set(OPENCV_INSTALL_FOLDER "../lib/install")
set(OPENCV_INCLUDE_FOLDER "${OPENCV_INSTALL_FOLDER}/include/opencv4/")
set(OPENCV_LIB_FOLDER "${OPENCV_INSTALL_FOLDER}/lib")
include_directories(${OPENCV_INCLUDE_FOLDER})
file(GLOB LIB_OPENCV "${OPENCV_LIB_FOLDER}/*.a" "${OPENCV_LIB_FOLDER}/opencv4/3rdparty/*.a")
# Project config
include_directories(src)
file(GLOB_RECURSE SRC_FILES src/*.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})
# Link libraries
target_link_libraries(${PROJECT_NAME} ${LIB_OPENCV})
# Set target properties for WebAssembly
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".wasm")
#include <fstream>
#include <iostream>
extern "C" {
void __cxa_throw(size_t, size_t, size_t) {
abort();
}
void* __cxa_allocate_exception(size_t) {
abort();
}
}
|
Note, the performing of this demo inside wasm is terrible, but works. If someone find a way to optimize it, It will help a lot |
Hi I am trying to compile the OpenCV source code (with the contrib modules) using WASI-SDK, as I was told by this issue that emscripten could not handle wasmtime (???).
So after following all the instructions of:
to install this SDK, and then going to my
~
folder where myopencv
andopencv_contrib
repos are at and doing:It gave me the following error:
I was hoping that integrating this SDK with a tried and true repository like OpenCV would be exemplary to see how this works.
I am on an Ubuntu 22.04 system. Ask me if you need any other information.
What should I do?
The text was updated successfully, but these errors were encountered: