Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Build external library and integrate with ACAP computer vision #119

Closed
Ahmed-Fayed opened this issue Nov 22, 2022 · 2 comments
Closed

Build external library and integrate with ACAP computer vision #119

Ahmed-Fayed opened this issue Nov 22, 2022 · 2 comments

Comments

@Ahmed-Fayed
Copy link

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

  • oatpp
  • libconfig

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
Copy link
Contributor

Corallo commented Dec 8, 2022

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
Copy link
Author

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

@AxisCommunications AxisCommunications locked and limited conversation to collaborators Jan 9, 2023
@Corallo Corallo converted this issue into discussion #123 Jan 9, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

2 participants