Skip to content

Compilation fails for Ubuntu 22.04 for static OpenCV build #677

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

Closed
B-Acharya opened this issue May 28, 2025 · 3 comments
Closed

Compilation fails for Ubuntu 22.04 for static OpenCV build #677

B-Acharya opened this issue May 28, 2025 · 3 comments

Comments

@B-Acharya
Copy link

Hey,

I’m trying to compile OpenCV from source. I used the following GitHub Actions workflow as a reference to adapt my build setup:
https://github.com/spoorn/media-to-ascii/blob/a01017fbb3dc883a89b0a1aff237c69b072542b2/.github/workflows/build.yml

My end goal is to run a Rust application that uses opencv-rust. However, I don’t have sudo access on the server, so I intended to build everything from source. That led to a chain of other dependencies also needing to be compiled manually.

To work around this, I switched to creating a Docker container where I could compile the software (with static build) more freely and then transfer the binaries to the server. Unfortunately, the build failed within the Docker container as well, even though I followed a similar approach and used the same source build method from the link above.
os: Ubuntu 22.04

At the moment, I'm encountering the following error:

Here's a short version :

 = note:  "cc" "/tmp/rustc9SdQwi/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/dummy/target/debug/deps/{libopencv-43f16b46c3719e5e.rlib,liblibc-64d6d99ae5042bc9.rlib,libnum_traits-9a3d33f79b1f1db1.rlib}.rlib" "<sysroot>/lib/rustlib/aarch64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lstdc++" "-lopencv_videoio" "-lopencv_imgcodecs" "-lopencv_imgproc" "-lopencv_core" "-lippiw" "-littnotify" "-lippicv" "-lz" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustc9SdQwi/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/dummy/target/debug/build/opencv-c67461ea4adcdbd7/out" "-L" "/opt/opencv/lib" "-L" "/opt/opencv/lib/opencv4/3rdparty" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "<sysroot>/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/dummy/target/debug/deps/dummy-62788e15c69e2488" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/bin/ld: cannot find -lippiw: No such file or directory
          /usr/bin/ld: cannot find -lippicv: No such file or directory
          /usr/bin/ld: cannot find -lz: No such file or directory
          collect2: error: ld returned 1 exit status

Here's the whole log from running cargo build -vv

out.log

Any hints on what might be going wrong or what could be updated would be greatly appreciated!

@twistedfall
Copy link
Owner

This particular error message indicates that you most probably don't have static libs for libz compression library and Intel IPP. It's difficult to say what exactly is missing on your system, but be sure to build your static OpenCV with at least -D BUILD_ZLIB=ON and -D OPENCV_FORCE_3RDPARTY_BUILD=ON or you can try disabling Intel IPP with -D WITH_IPP=OFF.

@B-Acharya
Copy link
Author

B-Acharya commented Jun 3, 2025

Thank you for your response.
I tried to understand the build process and I am somehow lost. Below Is the dockerfile that I use to create an Image to build opencv-rust. Opencv does compile but the rust application fails to build and is mainly dependancy errors, that it cannot find certain libraries.
Maybe I should set the OPENCV_LINK_PATHS to something else below to make it run ?
The easy solution would be to install all the libraries that are specified in install.sh, but would it then be portable ? I finally want to copy the binaries and run it on another linux machine without dependencies.

FROM ubuntu:22.04


ENV DEBIAN_FRONTEND=noninteractive

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive



# Install dependencies
# ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    build-essential \
    cmake \
    git \
    unzip \
    wget \
    clang \ 
    libclang-dev\
    wget \
    curl


RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

#RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
#    unzip -q opencv.zip && \
#    mv opencv-${OPENCV_VERSION} opencv
# Download and extract OpenCV and opencv_contrib 4.8.1
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.8.1.zip
RUN wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.8.1.zip
RUN unzip opencv.zip && rm opencv.zip 
RUN unzip opencv_contrib.zip && rm opencv_contrib.zip

# Build and install OpenCV statically to /opt/opencv
RUN mkdir -p /opencv-4.8.1/build && cd /opencv-4.8.1/build && \
    cmake -DCMAKE_BUILD_TYPE=Release \
          -D BUILD_CUDA_STUBS=OFF \
	        -D BUILD_DOCS=OFF \
	        -D BUILD_EXAMPLES=OFF \
	        -D BUILD_IPP_IW=ON \
	        -D BUILD_ITT=ON \ \
	        -D BUILD_JASPER=OFF \
	        -D BUILD_JAVA=OFF \
	        -D BUILD_JPEG=ON \
	        -D BUILD_OPENEXR=ON \
	        -D BUILD_OPENJPEG=ON \
	        -D WITH_OPENJPEG=OFF \
	        -D BUILD_PERF_TESTS=OFF \
	        -D BUILD_PNG=ON \
	        -D WITH_PNG=ON \
	        -D BUILD_PROTOBUF=ON \
	        -D BUILD_TBB=ON \
	        -D BUILD_TESTS=OFF \
	        -D BUILD_WEBP=ON \
	        -D BUILD_WITH_DEBUG_INFO=OFF \
	        -D BUILD_WITH_DYNAMIC_IPP=OFF \
	        -D BUILD_ZLIB=ON \
          -D WITH_ZLIB=ON \
	        -D BUILD_opencv_apps=OFF \
	        -D BUILD_opencv_python2=OFF \
	        -D BUILD_opencv_python3=OFF \
	        -D CMAKE_BUILD_TYPE=Release \
	        -D CMAKE_INSTALL_PREFIX=/opt/opencv \
	        -D CV_DISABLE_OPTIMIZATION=OFF \
	        -D CV_ENABLE_INTRINSICS=ON \
	        -D ENABLE_CONFIG_VERIFICATION=OFF \
	        -D ENABLE_FAST_MATH=OFF \
	        -D ENABLE_LTO=OFF \
	        -D ENABLE_PIC=ON \
	        -D ENABLE_PRECOMPILED_HEADERS=OFF \
	        -D INSTALL_CREATE_DISTRIB=OFF \
	        -D INSTALL_C_EXAMPLES=OFF \
	        -D INSTALL_PYTHON_EXAMPLES=OFF \
	        -D INSTALL_TESTS=OFF \
	        -D OPENCV_ENABLE_MEMALIGN=OFF \
	        -D OPENCV_ENABLE_NONFREE=ON \
	        -D OPENCV_FORCE_3RDPARTY_BUILD=OFF \
	        -D OPENCV_GENERATE_PKGCONFIG=OFF \
	        -D PROTOBUF_UPDATE_FILES=OFF \
	        -D WITH_ADE=ON \
	        -D WITH_ARAVIS=OFF \
	        -D WITH_CLP=OFF \
	        -D WITH_CUBLAS=OFF \
	        -D WITH_CUDA=OFF \
	        -D WITH_CUFFT=OFF \
	        -D WITH_EIGEN=ON \
	        -D WITH_GDCM=OFF \ \
	        -D WITH_GIGEAPI=OFF \
	        -D WITH_GSTREAMER_0_10=OFF \
	        -D WITH_GTK=OFF \
	        -D WITH_GTK_2_X=OFF \
	        -D WITH_HALIDE=OFF \
	        -D WITH_IMGCODEC_HDcR=ON \
	        -D WITH_IMGCODEC_PXM=ON \
	        -D WITH_IMGCODEC_SUNRASTER=ON \
	        -D WITH_INF_ENGINE=OFF \
	        -D WITH_IPP=OFF \
	        -D WITH_ITT=OFF \
	        -D WITH_JASPER=OFF \
	        -D WITH_JPEG=OFF \
	        -D WITH_LIBV4L=OFF \
	        -D WITH_MATLAB=OFF \
	        -D WITH_MFX=OFF \
	        -D WITH_OPENCL=OFF \
	        -D WITH_OPENCLAMDBLAS=OFF \
	        -D WITH_OPENCLAMDFFT=OFF \
	        -D WITH_OPENCL_SVM=OFF \
	        -D WITH_OPENEXR=OFF \
	        -D WITH_OPENMP=OFF \
	        -D WITH_OPENNI2=OFF \
	        -D WITH_OPENNI=OFF \
	        -D WITH_OPENVX=OFF \
	        -D WITH_PROTOBUF=ON \
	        -D WITH_PTHREADS_PF=ON \
	        -D WITH_PVAPI=OFF \
	        -D WITH_QUIRC=ON \
	        -D WITH_TBB=OFF \
	        -D WITH_TIFF=OFF \
	        -D WITH_UNICAP=OFF \
	        -D WITH_V4L=ON \
	        -D WITH_VA=ON \
	        -D WITH_VA_INTEL=ON \
	        -D WITH_VTK=ON \
	        -D WITH_WEBP=OFF \
	        -D WITH_XIMEA=OFF \
	        -D WITH_XINE=OFF \
	        -D WITH_XIMEA=OFF \
	        -D WITH_XINE=OFF \
          -D BUILD_SHARED_LIBS=OFF \
          -D BUILD_TIFF=ON \
          -D BUILD_opencv_freetype=OFF \
          -D OPENCV_FORCE_3RDPARTY_BUILD=ON \
          -D WITH_1394=OFF \
          -D WITH_FFMPEG=OFF \
          -D WITH_FREETYPE=OFF \
          -D WITH_GDAL=OFF \
          -D WITH_GPHOTO2=OFF \
          -D WITH_GSTREAMER=OFF \
          -D WITH_GTK=OFF \
          -D WITH_LAPACK=OFF \
          -D WITH_OPENGL=OFF \
          -D WITH_QT=OFF \
          -DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib-4.8.1/modules \
          .. && \
    cmake --build . --target install --config Release --parallel 8

#ENV OPENCV_LINK_LIBS="opencv_objdetect,opencv_videoio,opencv_imgcodecs,opencv_imgproc,opencv_core,libippiw,libittnotify,libippicv,z"
ENV OPENCV_LINK_LIBS="opencv_objdetect,opencv_videoio,opencv_imgcodecs,opencv_imgproc,opencv_core,z"
ENV OPENCV_LINK_PATHS=/opt/opencv/lib,/opt/opencv/lib/opencv4/3rdparty/lib,/usr/lib/x86_64-linux-gnu
ENV OPENCV_INCLUDE_PATHS=/opt/opencv/include,/opt/opencv/include/opencv4
ENV PKG_CONFIG_PATH="/opt/opencv/lib/pkgconfig:${PKG_CONFIG_PATH}"

# Add Rust cargo to PATH for the build process
# find / -type f -name cargo 2>/dev/null


RUN apt-get update && apt-get install -y --no-install-recommends \
      zlib1g-dev
WORKDIR /face-cropper
COPY . .  

ENV PATH="/root/.cargo/bin:${PATH}"

#RUN cargo build 

@B-Acharya
Copy link
Author

Update managed to build it by installing the respective packages. Thanks again for the first response it did help :)

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

2 participants