VSCode Application deployment with external libraries

Hello.
I am able to create and deploy the hello-world application using Toradex VScode Extension on VSCode. Now my application needs video file support so I compiled opencv and its dependencies within dev container. I was able to link successfully my application with libraries in dev container. However, while deploying the application the external libraries weren’t copied over to the board. What is best way to package the external libraries along with the application ? How to do in VSCode dev environment?
Thanks.

Greetings @azharq,

If you want certain libraries or packages in your application container you need to add these to the extrapackages option in the Torizon Extension configuration view. The devpacakges option only adds libraries/packages during the build stage but, not in the final application container. Of course the libraries or packages need to be available in the Debian package feeds.

Or are you referring to “external” libraries as in, libraries not available in the Debian package feed?

Best Regards,
Jeremias

Thanks @jeremias.tx !
I have quite a few libraries (opencv & dependencies). Do I have to add them individually in extrapackages? Can I add folders? Any example will help.

Also

Wait are you adding libraries from source or adding them via Debian packages? It sounds like you are doing the latter.

May I ask why you don’t just install the libraries from the Debian feeds? I believe these should be available. Unless you need a specific OpenCV version/library that isn’t available in Debian.

Otherwise you’d have to do something similar to what is shown on this page: How to Import a C/C++ Application to Torizon

This article integrates an external library (libspectrum) via source files.

Best Regards,
Jeremias

When I do this (in Dev container) …

RUN apt-get -y update && apt-get install -y
libavcodec-dev libavformat-dev libswscale-dev
libtbb2 libtbb-dev libjpeg-dev libpng-dev libdc1394-22-dev
libdc1394-22-dev protobuf-compiler libgflags-dev libgoogle-glog-dev
libblas-dev libhdf5-serial-dev liblmdb-dev libleveldb-dev liblapack-dev
libsnappy-dev libprotobuf-dev libopenblas-dev libboost-dev
libboost-all-dev libeigen3-dev libatlas-base-dev libne10-10 libne10-dev
libavcodec-dev libxvidcore-dev libx264-dev libv4l-dev libvpx-dev
&& apt-get clean && apt-get autoremove

It installs x86_64 version of libraries (not arm64). Therefore I am doing this to cross compile opencv for arm64
RUN git clone GitHub - opencv/opencv: Open Source Computer Vision Library && cd opencv
&& mkdir ./opencv_build && cd ./opencv_build
&& cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_TOOLCHAIN_FILE="…/platforms/linux/aarch64-gnu.toolchain.cmake"
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_GENERATE_PKGCONFIG=ON
-D WITH_FFMPEG=ON
-D INSTALL_C_EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF
-D BUILD_EXAMPLES=OFF
-D BUILD_PERF_TESTS=OFF
-D BUILD_TESTS=OFF
…/
&& make && make install

BTW in /appconfig_0/work folder there are “Dockerfile_SDK.debug” and “Dockerfile.debug” files. Should I install opencv and dependencies there?

Here is example for python-opencv :

which runs, but doesn’t have c/c++ header files. If I try to install libopencv-dev it refuses and reports conflicts.

Well I see what your issue is now. You’re modifying the Dockerfile directly. While possible this usually causes more issues as you’re meant to modify the project using the configuration options provided by our extension.

As I said earlier you add new packages to the dev container with devpackages, then you can add packages to the application container with extrapackages. In the package you can also specify which architecture of the package you want installed so it does not default to X86.

This is all described in detail in our C/C++ with VSCode article here: C/C++ Development and Debugging on TorizonCore Using Visual Studio Code

If you can make due with the standard packages from the Debian feeds rather than building in your libraries like this I would recommend it. It should help to reduce complexity and maintenance of your project.

I recommend going over the article I linked and using the extension as we recommend in that article.

Best Regards,
Jeremias

Hi @jeremias.tx .
Thanks this is very helpful. I added opencv library in devpackages as libopencv-dev:arm64. It rebuilt the SDK container fine. But the cmake command is showing error [find_package(OpenCV REQUIRED)]

CMake Error at /usr/lib/aarch64-linux-gnu/cmake/opencv4/OpenCVModules.cmake:476 (message):
[cmake] The imported target “opencv_gapi” references the file
[cmake]
[cmake] “/usr/lib/aarch64-linux-gnu/libopencv_gapi.so.4.4.0”
[cmake]
[cmake] but this file does not exist. Possible reasons include:
[cmake]
[cmake] * The file was deleted, renamed, or moved to another location.
[cmake]
[cmake] * An install or uninstall procedure did not complete successfully.
[cmake]
[cmake] * The installation package was faulty and contained
[cmake]
[cmake] “/usr/lib/aarch64-linux-gnu/cmake/opencv4/OpenCVModules.cmake”
[cmake]
[cmake] but not all the files it references.
[cmake]
[cmake] Call Stack (most recent call first):
[cmake] /usr/lib/aarch64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake:126 (include)
[cmake] CMakeLists.txt:19 (find_package)
[cmake]
[cmake]
[cmake] – Configuring incomplete, errors occurred!
[cmake] See also “/workspaces/tracking_demo_vivante/build/CMakeFiles/CMakeOutput.log”.

Hi @jeremias.tx .
I managed to build application by adding required devpackages and extrapackages. But when I launch the debugger it throws error dialog box and this error…

Local docker exception. :: Error (530) - Docker exception: The command ‘/bin/sh -c if [ ! -z “libopencv” ]; then apt-get -q -y update && apt-get -q -y install libopencv && rm -rf /var/lib/apt/lists/* ; fi’ returned a non-zero code: 100 code:100 message:The command ‘/bin/sh -c if [ ! -z “libopencv” ]; then apt-get -q -y update && apt-get -q -y install libopencv && rm -rf /var/lib/apt/lists/* ; fi’ returned a non-zero code: 100 Step 1/9 : FROM --platform=linux/arm64 torizon/wayland-base-vivante:2 —> fca9400ebd95 Step 2/9 : EXPOSE 6502 —> Using cache —> e9c9426bf59f Step 3/9 : ARG SSHUSERNAME=torizon —> Using cache —> 72e063e479d1 Step 4/9 : ENV DEBIAN_FRONTEND=“noninteractive” —> Using cache —> 8daed5714fcd Step 5/9 : RUN apt-get -q -y update && apt-get -q -y install gdbserver procps libxdamage1 libxfixes3 && rm -rf /var/lib/apt/lists/* —> Using cache —> 4d784e62ec80 Step 6/9 : RUN if [ …

I also verified that it is due to libopencv in extrapackages. If I remove it and the application doesn’t depend on it then the debugger launches properly.

Well according to the error message the issue is with building the application Docker container. In particular this part of the build:

The command ‘/bin/sh -c if [ ! -z “libopencv” ]; then apt-get -q -y update && apt-get -q -y install libopencv && rm -rf /var/lib/apt/lists/* ; 

Are you sure libopencv is a valid package in the Debian feeds? I checked here: https://packages.debian.org/search?searchon=names&keywords=libopencv

There doesn’t seem to be a package with the exact name libopencv. There is a libopencv-dev but not just libopencv. I see a libopencv-core4.5, perhaps that’s the package you are looking for?

Best Regards,
Jeremias

Thank you very much @jeremias.tx !
Adding libopencv-dev to extrapackages did the trick. Now two questions…

  1. How can I add my own libraries (.h and & .so files) to devpackages and extrapackages? Let’s say I build it using cmake within VSCode.
  2. How can I add input file needed by my application? so that it gets deployed and run with my application with the debugger.

Thanks and regards.

For both your questions, if you already have the files ready beforehand you can use the buildfiles configuration option. This option can be used to add additional files to the image using the ADD or COPY command. Files must be placed inside the application configuration folder (appconfig).

All the configuration options are described in detail here: C/C++ Development and Debugging on TorizonCore Using Visual Studio Code

Best Regards,
Jeremias

Thank you so much @jeremias.tx ! Closing the issue.

Glad I could help out!