Fixing Darknet OpenCV3 make error (convolutional_kernels)

So Darknet is a great open-source framework for deep learning including useful neural network implementations such as YOLO, ImageNet, RNNs etc but we have stumbled upon problems when trying to make it work with our system running CUDA 8.0 and OpenCV 3. It simply wouldn’t make, producing this error instead:

nvcc –gpu-architecture=compute_52 –gpu-code=compute_52  -DGPU -I/usr/local/cuda/include/ -DCUDNN  –compiler-options “-Wall -Wfatal-errors  -O0 -g -DGPU -DCUDNN” -c ./src/ -o obj/convolutional_kernels.o
/usr/include/c++/4.8/bits/stl_relops.h(85): error: this declaration may not have extern “C” linkage
Error limit reached.
100 errors detected in the compilation of “/tmp/tmpxft_00007d61_00000000-7_convolutional_kernels.cpp1.ii”.
Compilation terminated.
Makefile:98: recipe for target ‘obj/convolutional_kernels.o’ failed
make: *** [obj/convolutional_kernels.o] Error 4

Apparently this is a known issue when trying to build Darknet with OpenCV3 and is being discussed in Darknet google group:!topic/darknet/bXDkfGwU3CE. Most people ended up downgrading to OpenCV2 to make it work.

However just recently in October’2016, Prabindh Sundareson has posted his forked version of Darknet that resolves this problem: also available as a pull request to original code from PJReddie:

That version actually allows to build Darknet with GPU, cuDNN and full OpenCV3 support and we have tested it on Ubuntu 16.04 xenial.

Still it didn’t work out of the box using Prabindh’s update, for example we had a problem with nvcc resulting in this:

nvcc –gpu-architecture=compute_52 –gpu-code=compute_52  -DGPU -I/usr/local/cuda/include/ -DCUDNN  –compiler-options “-Wall -Wfatal-errors  -O0 -g -DGPU -DCUDNN” -c ./src/ -o obj/convolutional_kernels.o

/usr/local/cuda/include/surface_functions.h(134): error: expected a “;”

and other issues to do with environment and versioning so we decided to post the steps here in our blog so that others can benefit from them too:

  1. Clone the repo from Prabindh Sundareson (as of 13th November 2016 PJReddies hasn’t accepted this pull request into main repo of Darknet yet):
    git clone
  2. get the RC build from Nvidia ( For us this was tricky to find as NVidia search wouldn’t locate the file. Make sure you go into Member area or simply follow this link:
    sudo sh Downloads/ —override
    (in our case said “no” to driver and “yes” to samples as we had later driver version installed already)
  3. download “” patch from Nvidia as well. This patch fixes the NVCC / GCC versioning compiler issue but don’t install it yet if you’re in same situation like me, below:
    so in our case nvcc -V was still returning version “7.5” even after installing the 8.0.27 and above so if you have the same, make sure you set up the environment following instructions from “CUDA quick start guide for Ubuntu” or our steps below
  4. sudo sh Downloads/ –silent –toolkit –override
  5. export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  6. sudo nvidia-xconfig
  7. Then install cuDNN (re-install if like us you had it installed before)
    do something like:
    cd ~/Downloads/
    tar xvf cudnn*.tgz
    cd cuda
    sudo cp */*.h /usr/local/cuda/include/
    sudo cp */libcudnn* /usr/local/cuda/lib64/
    sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
  8. Only AFTER all above steps install the
    sudo sh /Downloads/
  9. Finally, go into darknet folder (Prabindh version you downloaded above) and build it:cd darknet make

Following the steps above allowed us to make and run Darknet with CUDA 8.0 and OpenCV3 installed, these are the parameters from Makefile:


Hope it helps, leave your questions or comments if any.

Best regards,

Covijn team.





  1. saurabh left a comment on May 6, 2017 at 9:08 am

    I have already installed cuda 8.0.61. now I am installing cuDNN from the site
    What version do I need to download.
    v6.0 requires a password for installation. So I am trying v5.1

    • saurabh left a comment on May 6, 2017 at 9:15 am

      ./src/cuda.c:140:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
      for(int i = 0;i < MAX_CUDNN;i ++)
      compilation terminated due to -Wfatal-errors.
      make: *** [obj/cuda.o] Error 1

      this is the error i am getting.

      • saurabh left a comment on May 6, 2017 at 9:27 am

        after debugging the above error
        by declaring int i outside the for loop.
        I am getting the following error

        ./src/image.c: At top level:
        ./src/image.c:508:29: error: unknown type name ‘CvCapture’
        image get_image_from_stream(CvCapture *cap)
        compilation terminated due to -Wfatal-errors.
        make: *** [obj/image.o] Error 1

  2. CarlLai left a comment on August 6, 2017 at 1:54 am

    I get the same error even after I have tried every steps you have provided.

  3. Jwalant Bhatt left a comment on July 19, 2018 at 3:36 pm

    Path Variable need to include :

    export PATH=/usr/local/cuda-9.2/bin${PATH:+:${PATH}}

    export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64\

    (add this to bash rc)
    (change to your cuda version)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.