0

I wanted to build opencv with gpu and the tutorial i particularly followed was Tutorial Link. Every time I build opencv with gpu using cmake, I come across the below error.

     usr/bin/x86_64-linux-gnu-ld: cannot find -llib64
     collect2: error: ld returned 1 exit status
     make[2]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:86:
     lib/libopencv_cudev.so.4.2.0] Error 1
     make[1]: *** [CMakeFiles/Makefile2:5326: modules/cudev/CMakeFiles/opencv_cudev.dir/all] Error 2
     make[1]: *** Waiting for unfinished jobs....

After referring many posts, some say it has to do with opencv.cmake, while others it has to be with the compiler. link1,link2link3. I am still stuck and couldn't make any progress for couple of days. If you have come across such error, please help me on how to solve it.

The config i am using

Graphic Card: NVIDIA GTX 1070

cuda library: cuda10.1

compiler: g++-6

python: 3.8

operating system: ubuntu20.04

The command I used to build it is given below

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/opt/opencv \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D WITH_CUDA=ON \
    -D WITH_CUDNN=ON \
    -D CMAKE_C_COMPILER=/usr/bin/gcc-6 \
    -D CMAKE_CXX_COMPILER=/usr/bin/g++-6 \
    -D OPENCV_DNN_CUDA=ON \
    -D ENABLE_FAST_MATH=1 \
    -D CUDA_FAST_MATH=1 \
    -D CUDA_ARCH_BIN=6.1 \
    -D CUDNN_INCLUDE_DIR=/usr/lib/cuda/include \
    -D CUDNN_LIBRARY=/usr/lib/cuda/lib64 \
    -D WITH_CUBLAS=1 \
    -D OPENCV_EXTRA_MODULES_PATH=/home/james/Installers/opencv/opencv_contrib/modules \
    -D HAVE_opencv_python3=ON \
    -D PYTHON_EXECUTABLE=~/.virtualenvs/opencv_cuda/bin/python \
    -D PYTHON_DEFAULT_EXECUTABLE=<path/to/desired/python/environment>/bin/python3.5
    -D PYTHON_INCLUDE_DIRS=<path/to/desired/python/environment>/include/python3.5m
    -D PYTHON_EXECUTABLE=<path/to/desired/python/environment>/bin/python3.5
    -D PYTHON_LIBRARY=<path/to/desired/python/environment>libpython3.5m.so.1
    -D BUILD_EXAMPLES=ON ..

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Sun_Jul_28_19:07:16_PDT_2019 Cuda compilation tools, release 10.1, V10.1.243

Any tips would be greatly helpful .

James K J
  • 605
  • 1
  • 8
  • 20
  • What is the output of the command `nvcc --version` ? – Yunus Temurlenk Aug 28 '20 at 10:40
  • `-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.1 ` This is also not included and why ur location on cmake `/usr/lib` instead of `/usr/local` ? – Yunus Temurlenk Aug 28 '20 at 10:49
  • @YunusTemurlenk. To install cuda, i followed the below tutorial https://askubuntu.com/questions/1230645/when-is-cuda-gonna-be-released-for-ubuntu-20-04 – James K J Aug 28 '20 at 10:58
  • @YunusTemurlenk. I have updated the answer for nvcc – James K J Aug 28 '20 at 11:01
  • I am not totally sure **BUT** as the documentation says it should be installed to `/usr/local` I advise you to follow this guidances: [here](https://docs.nvidia.com/cuda/archive/10.1/index.html) and [here](https://docs.nvidia.com/cuda/archive/10.1/cuda-installation-guide-linux/index.html). The requirements saying that Operating system supports lover or equal to 18.04 but dont mind it, it ll probably work on 20.04 also. Also why in your cmake you are using gcc-6. This also weird – Yunus Temurlenk Aug 28 '20 at 11:07
  • @YunusTemurlenk When i compile with gcc-9, the wired errors. Then i googled it and i was advised to run on gcc-6. – James K J Aug 28 '20 at 11:09
  • Its not safe to change gcc version of a current operating system. I am surprised ur OS still didnt crash. You probably add gcc-6 additionally, you didnt change gcc-9, it also still exist – Yunus Temurlenk Aug 28 '20 at 11:12
  • yes, it still exist – James K J Aug 28 '20 at 11:16
  • 2
    @YunusTemurlenk. I solved it. Instead of setting -D CUDNN_LIBRARY=/usr/lib/cuda/lib64, i changed to -D CUDNN_LIBRARY=/usr/lib/cuda/lib64/libcudnn.so.7.6.5 – James K J Aug 28 '20 at 12:03

1 Answers1

0

i replace all -llib64 to -L/usr/local/cuda/lib64 -lcudnn using find and sed in build opencv dir:
find -name link.txt -exec sed -i -e 's/-llib64/-L\/usr\/local\/cuda\/lib64 -lcudnn/g' {} \;

mutex2201
  • 1
  • 2