Failed libopencv_cudaobjdetect.so library due to 150 minutes of inactivity

Hi Nvidia Team,
I am trying to enable CUDA for OpenCV building from source (the Debian way of building) and also doing the cross-compile from the powerful server. I am cross compiling OpenCV for Jetson Orin Nano platform.

rules.txt (8.8 KB)

I have attached the rules file, which is getting used during the configuration & building of OpenCV.

So, I am suspecting the NVCC build is taking more time during the build, due to which this package might fail. I have used -DCUDA_NVCC_FLAGS=“–threads 32” but I am not sure if any other parameters also need to be passed in OpenCV. Also, I am using 32 threads here. I need to increase this or decrease it to get better build speed.

Please help me to review the Debian rules file once and update me on what I have to use to get a better build speed and will not get a problem like this.

[1312/1355] : && /usr/bin/aarch64-linux-gnu-g++ -fPIC -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -Wno-undef -Wno-missing-declarations -Wno-shadow -Wno-strict-aliasing -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG  -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libopencv_cudaobjdetect.so.410 -o lib/libopencv_cudaobjdetect.so.4.10.0 modules/cudaobjdetect/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_hog.cu.o modules/cudaobjdetect/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_lbp.cu.o modules/cudaobjdetect/CMakeFiles/opencv_cudaobjdetect.dir/src/cascadeclassifier.cpp.o modules/cudaobjdetect/CMakeFiles/opencv_cudaobjdetect.dir/src/hog.cpp.o -L/usr/local/cuda/lib64 lib/libopencv_cudawarping.so.4.10.0  lib/libopencv_cudalegacy.so.4.10.0  -ldl  -lm  -lpthread  -lrt  -lcudart_static  -ldl  -lrt  -lnppc  -lnppial  -lnppicc  -lnppidei  -lnppif  -lnppig  -lnppim  -lnppist  -lnppisu  -lnppitc  -lnpps  -lcublas  -lcufft  -L/usr/local/cuda/lib64  -L/usr/lib/aarch64-linux-gnu  -lcudart_static  -ldl  -lrt  -lnppc  -lnppial  -lnppicc  -lnppidei  -lnppif  -lnppig  -lnppim  -lnppist  -lnppisu  -lnppitc  -lnpps  lib/libopencv_cudaimgproc.so.4.10.0  lib/libopencv_cudafilters.so.4.10.0  lib/libopencv_cudaarithm.so.4.10.0  lib/libopencv_objdetect.so.4.10.0  lib/libopencv_video.so.4.10.0  lib/libopencv_dnn.so.4.10.0  lib/libopencv_calib3d.so.4.10.0  lib/libopencv_features2d.so.4.10.0  lib/libopencv_flann.so.4.10.0  lib/libopencv_imgproc.so.4.10.0  lib/libopencv_core.so.4.10.0  lib/libopencv_cudev.so.4.10.0  -lm  -lpthread  -lcublas  -lcufft  -Wl,-rpath-link,/<<PKGBUILDDIR>>/obj-aarch64-linux-gnu/lib && :
[1313/1355] /usr/bin/cmake -E cmake_symlink_library lib/libopencv_cudaobjdetect.so.4.10.0  lib/libopencv_cudaobjdetect.so.410 lib/libopencv_cudaobjdetect.so && :
E: Build killed with signal TERM after 150 minutes of inactivity
--------------------------------------------------------------------------------
Build finished at 2025-02-25T23:15:15Z

+------------------------------------------------------------------------------+
| Finished Timed Build Commands                                                |
+------------------------------------------------------------------------------+


rm -f /var/cache/apt/archives/sbuild-build-depends-main-dummy_*.deb
-------------------------------------------------------------------


I: Finished running 'rm -f /var/cache/apt/archives/sbuild-build-depends-main-dummy_*.deb'.

find /var/cache/apt/archives -maxdepth 1 -type f -name '*.deb' -print -exec cp -Ln --no-preserve=owner -t /home/builder/opencv/rootfs/var/cache/apt/archives/ {} +
------------------------------------------------------------------------------------------------------------------------------------------------------------------


I: Finished running 'find /var/cache/apt/archives -maxdepth 1 -type f -name '*.deb' -print -exec cp -Ln --no-preserve=owner -t /home/builder/opencv/rootfs/var/cache/apt/archives/ {} +'.

cp /var/log/dpkg.log /home/builder/opencv/rootfs/dpkg_partial.log
-----------------------------------------------------------------


I: Finished running 'cp /var/log/dpkg.log /home/builder/opencv/rootfs/dpkg_partial.log'.

Finished processing commands.
--------------------------------------------------------------------------------

Finished
--------


+------------------------------------------------------------------------------+
| Cleanup                                                                      |
+------------------------------------------------------------------------------+

Purging /<<BUILDDIR>>
Not cleaning session: cloned chroot in use
E: Build failure (dpkg-buildpackage died)

+------------------------------------------------------------------------------+
| Summary                                                                      |
+------------------------------------------------------------------------------+

Build Architecture: amd64
Build Profiles: cross cross
Build Type: binary
Build-Space: 12672448
Build-Time: 16492
Distribution: isar
Fail-Stage: build
Foreign Architectures: armhf arm64
Host Architecture: arm64
Install-Time: 115
Job: /build/tmp/work/industrial-os-arm64/opencv/4.10.0-ind1/opencv_4.10.0+dfsg-1.dsc
Machine Architecture: amd64
Package: opencv
Package-Time: 16617
Source-Version: 4.10.0+dfsg-1
Space: 12672448
Status: attempted
Version: 4.10.0+dfsg-1
--------------------------------------------------------------------------------
Finished at 2025-02-25T23:15:15Z
Build needed 04:36:57, 12672448k disk space
E: Build failure (dpkg-buildpackage died)
WARNING: exit code 2 from a shell command.
DEBUG: Executing shell function schroot_delete_configs
Removing /etc/schroot/mel-builder-ac991f03-882f-47ca-8d1d-a58ec9d16530-44938
Removing /etc/schroot/chroot.d/mel-builder-ac991f03-882f-47ca-8d1d-a58ec9d16530-44938
DEBUG: Shell function schroot_delete_configs finished
DEBUG: Python function do_dpkg_build finished

Hi,

We suggest using our cross-compiling container to compile a Jetson app/library.

Thanks.

Hi,

Instead of building it from the source, you can also find the OpenCV with CUDA enabled in the below link:

Thanks

Hi @AastaLLL,

Thanks for the response, but I am unable to use this Jetpack cross-compiling container as we are having another way to build packages. But I have given a try to use this cross-compiling container for building OpenCV with CUDA enabled to calculate the build time with the Jetson cross-compiling container but was unable to do so as I have not been able to find out how I can do cross-compiling for OpenCV in the Jetson cross-compiling container.

Can you suggest how I can cross-compile OpenCV in the Jetson cross-compiling container? So that I can compare the time taken by the build in our setup and the Jetson cross-compiling container.

Regarding this pypi.jetson-ai-lab.dev
I am not sure that I can use this directly as previously I am pulling OpenCV from Index but when I develop OpenCV based app then I got crashes as our Debian system having higher version of libs and pulled OpenCV builded against the ubuntu system based dependencies. So I don’t want to have problem at the last moment. Here is the example ref error reported by our sample test app.

root@orin-nano:~# python3.10 stream.py
Traceback (most recent call last):
  File "/root/stream.py", line 1, in <module>
    import cv2
  File "/usr/lib/python3.10/dist-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/lib/python3.10/dist-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libavcodec.so.58: cannot open shared object file: No such file or directory

Thanks,

Ritesh

Hi,

Do you use JetPack 6.1 or 6.2?
We can find the library under the below folder:

$ sudo find / -iname libavcodec.so*
/usr/lib/aarch64-linux-gnu/libavcodec.so.58
/usr/lib/aarch64-linux-gnu/libavcodec.so
/usr/lib/aarch64-linux-gnu/libavcodec.so.58.134.100

Is the cross-compiling essential for you?
We also have some automatic scripts that can build OpenCV with CUDA support on Jetson natively.
Although it takes hours to finish, the script can automatically install all the requirements without manual steps.

Thanks.

Hi @AastaLLL ,
I am not saying that I don’t have libavcodec I have this but the higher version which is provided by Debian 12 (bookworm). problem is I don’t have libavcodec.so.58.

root@orin-nano:~# find / -iname libavcodec.so*
/usr/lib/aarch64-linux-gnu/libavcodec.so
/usr/lib/aarch64-linux-gnu/libavcodec.so.59
/usr/lib/aarch64-linux-gnu/libavcodec.so.59.37.100

So, I have decided to do Cross compile to have error free app development for any case.

https://github.com/AastaNV/JEP/tree/master/script
This I have explored and am able to generate libs in Jetson Orin itself, but we want to have OpenCV libs included in our final bootable image. So I am trying to do cross-compilation of OpenCV, and the current status is I have done the OpenCV cross-compilation for Jetson Orin in our Debian-based image. The only problem I am facing is when I enable CUDA in OpenCV, getting this problem (E: Build killed with signal TERM after 150 minutes of inactivity).

Thanks,
Ritesh

Hi,

It looks like there is no DCMAKE_TOOLCHAIN_FILE set in your environment.
Could you set the variable and try it again?

Another alternative is to build OpenCV on Orin Nano locally.
And cloning the image to flash other devices.

Thanks.

Hi @AastaLLL ,
I am able to do cross compile but when I am enabling CUDA in Opencv having issue like failed to build as timeout happened. I have not check the OpenCV way of cross compiling, I am working on it and I will update whether it will work or not when we enable cuda in that.

Thanks,
Ritesh

Hi,

Usually, we recommend building it directly on the target as it solves most of the compatibility issues.
You can either copy the package or clone the whole image for the next time flashing.

Thanks.