Ask Your Question

Issues compiling opencv-3.4.8 with cuda-10.2 in Ubuntu

asked 2020-01-29 21:31:07 -0500

Did anyone successfully compile opencv-3.4.x successfully with cuda 10.2?

It seems that cudu 10.2 has made some changes that breaks the opencv compilations.

**System description:**
OS: Ubuntu 18.04 LTS
Platform: Nvidia Drive AGX
CPU: aarch64
Cuda: 10.2
Cmake: 3.16.3

cmake command:

cmake \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=OFF \
-DWITH_1394=OFF \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DCUDA_cufft_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppc_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_npps_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppial_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppicc_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppicom_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppidei_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppif_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppig_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppim_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppist_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppisu_LIBRARY=/usr/local/cuda/lib64/ \
-DCUDA_nppitc_LIBRARY=/usr/local/cuda/lib64/ \

Output from console:

-- General configuration for OpenCV 3.4.8 =====================================
--   Version control:               unknown
--   Platform:
--     Timestamp:                   2020-01-30T02:15:35Z
--     Host:                        Linux 4.14.102-rt53-tegra aarch64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
--   CPU/HW features:
--     Baseline:
--       requested:                 NEON FP16
--       disabled:                  VFPV3 NEON
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++11:                       YES
--     C++ Compiler:                /usr/bin/c++  (ver 7.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -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 -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -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 -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections  
--     Linker flags (Debug):        -Wl,--gc-sections  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc npps cublas cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
--   OpenCV modules:
--     To be built ...
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-04-17 09:59:19 -0500

DanK gravatar image

I was struggling with this same issue and needed opencv 3.4 with cuda 10.2. Tooks some digging but I believe I figured out what you need to do. It turns out that the opencv cmake search stuff use to deduce the CUDA information is reliant on a number of variables that do not normally get set, mostly because the root path of cuda was all that was needed. I found that if I declare the following setup of environmental variables, I am able to build OpenCV with CUDA enabled without much hassle.

I create the file It's contents follow:

# location of cuda installation     

# location of lib & include paths  (this is what has changed in newer cuda setups)

# location of nvcc




The big ones to make sure are set are CUDA_PATH, CUDA_BIN_PATH, CUDA_LIB_PATH, CUDA_INC_PATH I created the other ones for myself.

If you search through all the cmake files, these variables help cmake properly configure compilation of opencv when available. What I have found is the newer versions of CUDA changed the location of the lib & include paths and that seemed to have broken the search and find parts of cmake. Setting these variables fixes that.

The last thing you should do if compiling opencv with CUDA is declare -DWITH_NVCUVID=OFF unless you are sure you have the prerequisites installed and in the correct places. If this is not set to off, the compilation of cuda fails when it searches for a header associated with this option. I've not used this feature so my process turns it off.

I generally add the '' to /etc/profile.d on my system as adminstrator so these parameters are set for the system.

Hope this helps.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-01-29 21:31:07 -0500

Seen: 712 times

Last updated: Jan 29 '20