AxisCommunications / acap-computer-vision-sdk-examples

Axis Camera Application Platform (ACAP) version 4 example applications that provide developers with the tools and knowledge to build their own solutions based on the ACAP Computer Vision SDK
Apache License 2.0
50 stars 23 forks source link

Build external library and integrate with ACAP computer vision #119

Closed Ahmed-Fayed closed 1 year ago

Ahmed-Fayed commented 1 year ago

Issue description

I'm trying to build an external libraries and integrate them with object-detector-cpp example in ACAP-Computer-Vision-SDK but I get this error

integration_1_error

External Libraries

Dockerfile


# syntax=docker/dockerfile:1

ARG ARCH=armv7hf
ARG REPO=axisecp
ARG SDK_VERSION=1.4
ARG UBUNTU_VERSION=22.04

FROM arm32v7/ubuntu:${UBUNTU_VERSION} as runtime-image-armv7hf
FROM arm64v8/ubuntu:${UBUNTU_VERSION} as runtime-image-aarch64

FROM ${REPO}/acap-computer-vision-sdk:${SDK_VERSION}-${ARCH} as cv-sdk-runtime
FROM ${REPO}/acap-computer-vision-sdk:${SDK_VERSION}-${ARCH}-devel as cv-sdk-devel

# Setup proxy configuration
ARG HTTP_PROXY
ENV http_proxy=${HTTP_PROXY}
ENV https_proxy=${HTTP_PROXY}

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y -f libglib2.0-dev libsystemd0 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir -p /tmp/devel /tmp/runtime /build-root /target-root

# Download the target libs/headers required for compilation
RUN apt-get update && apt-get install --reinstall --download-only -o=dir::cache=/tmp/devel -y -f libglib2.0-dev:$UBUNTU_ARCH \
    libsystemd0:$UBUNTU_ARCH \
    libgrpc++-dev:$UBUNTU_ARCH \
    libprotobuf-dev:$UBUNTU_ARCH \
    libc-ares-dev:$UBUNTU_ARCH \
    libgoogle-perftools-dev:$UBUNTU_ARCH \
    libssl-dev:$UBUNTU_ARCH \
    libcrypto++-dev:$UBUNTU_ARCH \
    libgcrypt20:$UBUNTU_ARCH

RUN for f in /tmp/devel/archives/*.deb; do dpkg -x $f /build-root; done
RUN cp -r /build-root/lib/* /build-root/usr/lib/ && rm -rf /build-root/lib

# Separate the target libs required during runtime
RUN apt-get update && \ 
    apt-get install --reinstall --download-only -o=dir::cache=/tmp/runtime -y -f libgrpc++:$UBUNTU_ARCH \
    '^libprotobuf([0-9]{1,2})$':${UBUNTU_ARCH} \
    libc-ares2:$UBUNTU_ARCH

RUN for f in /tmp/runtime/archives/*.deb; do dpkg -x $f /target-root; done
RUN cp -r /target-root/lib/* /target-root/usr/lib/ && rm -rf /target-root/lib

WORKDIR /build-root
RUN git clone https://github.com/oatpp/oatpp.git && \
    cd oatpp && \
    mkdir build && cd build && \
    cmake -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ \
    -D OATPP_DISABLE_ENV_OBJECT_COUNTERS=ON \
    -D OATPP_BUILD_TESTS=OFF .. && \
    make install

ARG BUILDDIR=/build-root/oatpp/build
RUN cp -r ${BUILDDIR}/src/liboatpp* /target-root/usr/lib

WORKDIR /build-root
RUN git clone https://github.com/hyperrealm/libconfig.git
WORKDIR /build-root/libconfig
RUN autoreconf -i && ./configure &&\
    gCFLAGS=' -O2 -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fomit-frame-pointer' \
    CC=arm-linux-gnueabihf-gcc cmake -G"Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ . && \
    make -j;

ARG BUILDDIR=/build-root/libconfig/out
RUN cp -r ${BUILDDIR}/libconfig.so* /target-root/usr/lib &&\
    cp -r ${BUILDDIR}/libconfig++.so* /target-root/usr/lib

COPY app/Makefile /build/
COPY app/src/ /build/src/
WORKDIR /build
RUN make

FROM runtime-image-${ARCH}
# Copy the libraries needed for our runtime
COPY --from=cv-sdk-devel /target-root /

# Copy the compiled object detection application
COPY --from=cv-sdk-devel /build/objdetector /usr/bin/

# Copy the precompiled opencv libs
COPY --from=cv-sdk-runtime /axis/opencv /

# Copy the precompiled openblas libs
COPY --from=cv-sdk-runtime /axis/openblas /

CMD ["/usr/bin/objdetector"]

Makefile


# Application Name
TARGET := objdetector

# Function to recursively find files in directory tree
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

# Find all .o files compiled from protbuf files
PROTO_O := $(call rwildcard, /axis/tfproto, *.o)

# Determine the base path
BASE := $(abspath $(patsubst %/,%,$(dir $(firstword $(MAKEFILE_LIST)))))

# Find cpp files
OBJECTS := $(patsubst %.cpp, %.o, $(wildcard $(BASE)/src/*.cpp))
OTHEROBJS = $(BASE)/src/*/*.cpp

CXX = $(TARGET_TOOLCHAIN)-g++
CXXFLAGS += -I/usr/include -I/usr/include/grpcpp/security -I/axis/tfproto -I/axis/openblas/usr/include -I/axis/opencv/usr/include -I/build-root/usr/include
CXXFLAGS += -I/build-root/oatpp/src
CXXFLAGS += -I/build-root/libconfig/lib

CPPFLAGS = --sysroot=/build-root $(ARCH_CFLAGS) -Os -pipe -std=c++17
STRIP=$(TARGET_TOOLCHAIN)-strip

SHLIB_DIR = /target-root/usr/lib
LDFLAGS = -L$(SHLIB_DIR) -Wl,--no-as-needed,-rpath,'$$ORIGIN/lib'
LDLIBS += -L $(BASE)/lib \
 -L /axis/opencv/usr/lib \
 -L /axis/openblas/usr/lib
LDLIBS += -lm -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopenblas -lgfortran
LDLIBS += -lprotobuf -lz -lgrpc -lgpr -lgrpc++ -lssl -lcrypto -lcares -lprofiler -lrt
LDLIBS += -lvdostream -lfido -lcapaxis -lstatuscache 
SHLIBS += -loatpp -lconfig++

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJECTS)
    $(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) $(SHLIBS) $(OTHEROBJS) $(PROTO_O) -o $@ && $(STRIP) --strip-unneeded $@

clean:
    $(RM) *.o $(TARGET)
Corallo commented 1 year ago

Hi Ahmed

The first thing that I recommend you to check is to enter with bash in your docker container and see if you find those shared libraries where they are expected to be. Also, do you get any warnings during the build?

Ahmed-Fayed commented 1 year ago

Hi Corallo

Thanks for your reply, I don't get any warnings during the build, I will check those shared libraries again as you recommend and see if they are in the expected path