Installing OpenCV 3.1.0 on Ubuntu

Itseez has finally released the first stable version of OpenCV in the 3.x series. It promises many new features over the 2.x version and many bug fixes over version 3.0. So if you want to install this new version, whether you  already have an older version installed or you just want to install it on a fresh GNU/Linux machine…you have come to the right place!

Removing  older versions of OpenCV

There are 2 methods of removing your old installation of OpenCV, and they depend on how have you had OpenCV installed in first place!

1- If you have installed from Ubuntu’s repository (or package managers like apt or the package manager of any other distros)

In this case, it is as simple as removing OpenCV’s package using your package manager. For example, on Ubuntu based Linux systems you can write the following commands in your favorite terminal. Pres TAB a few times to see which packages are related to open cv:

2-If you have installed from source (using make/make install):

In this case, the make command should have created an uninstall profile for you. So to remove OpenCV, go to the folder that you have compiled OpenCV (the place you had called make/make install) and execute the following command:

NOTE: If you do not remember how have you installed OpenCV, or none of the above method works for you, you can use the following command to delete any file that has something to do with OpenCV. Please note that removing files can be dangerous so do this on your own risk! I take no responsibility! 🙂

The first command will look for any file that contains “opencv” in its name and will remove it. The second line will update the linker cache to possibly reflect the removal of OpenCV and update the shared libraries.

Installing OpenCV 3.1.0 And opencv-contrib packages

First of all, please noet that the following guide has been taken from the OpenCV documentation itself, but with minor changes required to install version 3.1.0 and contrib package of OpenCV.

Preparation

The very first step is to make sure you have required packages (build tools like gcc compiler, cmake, git, etc.). Use the following commands to download the required packages (do not be worried, if you already have them the package manager will not download or install already existing packages)

First, build tools:

Then the required packages:

*Optional packages:

Downloading OpenCV source files

I assume that you want to download sources into “/opt/” folder. Feel free to change the base directory to wherever you want (granted that you have write access) but make sure to reflect the changes in the code snippets below!.

Clone OpenCV’s git repository:

After this, stay in the “/opt” folder and clone the contrib repository as well (if you need the extra packages)

After cloning both repositories, you will have two folders. First “opencv” and second “opencv_contrib”. Now you have to go to each folder and make sure to checkout the version 3.1.0 branch for both of them (It is important that the version of OpenCV and OpenCV Contrib packages match!):

As of Jun 2016 please leave both the opencv and opencv_contrib repositories to stay on Master branch. you do not need to check out 3.1.0…the code snippets are just here for example! do not checkout other branches!

The last command should bring you inside the opencv folder. Get ready for the configuration and compilation step!

Pre-Build Configuration

Before compiling OpenCV from source, we need to perform some configuration to let the compiler know what we need it to compile for us! The first step is to create a directory for the compiler to put the complied files there for us. I call this “release” directory:

Now we have to let the “cmake” build system know how we want to configure the OpenCV for compilation, while you are in the release folder, type the following command:

What the command above does, is to tell the cmake that we want to compile a release version, we want the resulted library files to be copied to /usr/local (this is where most shared libraries are installed on a GNU/Linux system) and finally we tell the cmake where the contirb package modules are located. If you do not want to install contrib packages, remove the last option. Finally as I told before, the double dot tells the cmake that source codes are one folder up in the folder structure! After this step, you should see some files and folders in the release folder (as well as the “Makefile” generatd by cmake).

Note that this is default configuration. If you want to have FFMPEG and CUDA support, you have to first install these libraries and edit the CMakeCache.txt to enable these features!

Make and install

This is the final step. The only thing you need to do is to call “make” command in release folder, wait for compilation (it might take up to one hour depending on your computer’s processing power!) and finally install the compiled libraries by calling “make install”. To do so:

That’s all folks! hopefully if you have done everything right, your installation should be done by now! To check, run the following command:

It should print out “3.1.0”…

Common Problems

Judging from comments on this guide and my YouTube channel, The most common problems are:

  • Old version of GCC! Please make sure you have a recent version of GCC (I recommend 4.8.X or higher)
  • You did not install all the required packages! Please install the packages (find them in the beginning of the article)
  • You executed the cmake in the wrong directory, or you pointed the sources to an invalid location
Whats next?

Please stay tuned, as I am working on preparing some tutorials on using OpenCV in conjunction with QtQuick on Linux!

Saeid Yazdani

An Electronics Engineer with passion in Embedded Systems, Wireless Sensor Networks, Assembly, Desktop and Mobile Development, Web Development and generally anything that has to do with hardware and software of any kind!

112 Comments:

  1. Thanks for the tutorial. This makes things easier for me.

      • oi amigo,não consigo resolver esse problema …. [ 7%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/va_intel.cpp.o
        [ 8%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/opencl_kernels_core.cpp.o
        make[2]: *** Sem regra para processar o alvo /usr/lib/libz.so', necessário por lib/libopencv_core.so.3.1.0′. Pare.
        make[1]: ** [modules/core/CMakeFiles/opencv_core.dir/all] Erro 2
        make: ** [all] Erro 2
        root@ozigod-System-Product-Name:/home/ozigod/Transferências/op/opencv-3.1.0/release# chmod 777 /usr/lib/libz.so
        chmod: impossível operar sobre ligação simbólica «/usr/lib/libz.so»

  2. Hi. I had a problem. when I try to give the make command I get the following error:make: *** No targets specified and no makefile found. Stop.

    what can I do about this?

    • Hey, It is most likely you have not executed the “cmake” step. This error is due to the fact that “Makefile” has not been generated by “cmake” or you are simply on the wrong folder…

      Please make sure you make a folder and do the cmake and make steps inside that folder.

      • Even I got the same problem. when I get cmake i get the error ” configuring incomplete error occured” How to resolve this problem.

        • Is that the only line of error you get? there should be more details…please paste them all here. But I think you have missed some steps…maybe you have not installed the prerequisite packages, or you forgot to checkout the 3.1.0 branch for both OpenCV and contrib repositories, or you have not executed the right cmake command.

          Also make sure you are in the right folder when executing the cmake command. And as I emphasized in the article make sure the double dot at the end of cmake command is present, or instead of double dot, write the actual physical path.

          • Hi, i followed this steps:-

            mkdir build &&
            cd build &&

            cmake -DCMAKE_INSTALL_PREFIX=/usr \
            -DWITH_XINE=ON \
            -DBUILD_TESTS=OFF \
            -Wno-dev ..
            make

            still i found the same error:
            make: *** No targets specified and no makefile found. Stop.

            what cam i do about this?

          • You are on the wrong folder

        • Hi!
          I am getting the same problem . I have checked properl i am in right folder and the command is also as it is in tutorial. No idea how to proceed

  3. Thanks a lot 🙂

  4. Instead of cloning with git I preferred to download and extract the tar.gz for version 3.1.0 of opencv and opencv_contrib (lighter than the whole project) and work from there.

    When running make (in the “Make and Install” section of the tutorial) I get the message “fatal error: hdf5.h: No such file or directory”. According to https://gist.github.com/wangruohui/679b05fcd1466bb0937f it’s an Ubuntu 15.10’s naming problem. hdf5 is installed and apparently I just need to tell make where to find it. The option -Idir didn’t work for me (?).

    I had to modify the file /opencv_contrib-3.1.0/modules/hdf/include/opencv2/hdf/hdf5.hpp in line 40:

    --- #include
    +++ #include "/usr/include/hdf5/serial/hdf5.h"

    This workaround I found is definitely not very elegant, but after that everything went smoothly. Thanks for the tutorial.

  5. Hi!! i got the following error while installing opencv 3.1.0 … it is the error that comes at compile time of opencv by make command

    Linking C static library ../lib/liblibjasper.a
    [ 10%] Built target libjasper
    Scanning dependencies of target IlmImf
    [ 10%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/Half/half.cpp.o
    /opt/opencv/3rdparty/openexr/Half/half.cpp:57:21: error: /opt/opencv/3rdparty/openexr/Half/toFloat.h: Input/output error
    #include "toFloat.h"
    ^
    In file included from /opt/opencv/3rdparty/openexr/Half/half.cpp:48:0:
    /opt/opencv/3rdparty/openexr/Half/half.h:99:31: error: expected primary-expression before ‘const’
    #define HALF_EXPORT_CONST const
    ^
    /opt/opencv/3rdparty/openexr/Half/half.cpp:58:1: note: in expansion of macro ‘HALF_EXPORT_CONST’
    HALF_EXPORT_CONST unsigned short half::_eLut[1 << 9] =
    ^
    make[2]: *** [3rdparty/openexr/CMakeFiles/IlmImf.dir/Half/half.cpp.o] Error 1
    make[1]: *** [3rdparty/openexr/CMakeFiles/IlmImf.dir/all] Error 2
    make: *** [all] Error 2

    please help me to remove this problem..

    • Input/Output error by GCC means that either that file, here “toFloat.h” is not present or it is corrupted or you have a disk failure. Make sure that the file exist in the suggested path and make sure your disk has not any problems.

  6. Can I remove folders /opt/opencv and /opt/opencv_contrib after installation?

    • Yes, but make sure you move the release folder that the compile is done in it somewhere safe so you can later call “make uninstall” if you ever need to uninstall opencv.

  7. hi
    thank you for your post so useful
    i have problem with making opencv to work with netbeans no matters what project properties i set i just getting errors.

    • Hi, I cant really say anything ….what kind of errors? It might be related to GCC not finding library/header files. I use Qt Creator myself with following settings:


      INCLUDEPATH += /usr/local/include/opencv
      LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_imgproc

  8. Hi!! i got the following error while installing opencv 3.1.0 … it is the error that comes at compile time of opencv by make command.

    [ 25%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap _gphoto2.cpp.o
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:171: error: ISO C++ fo rbids initialization of member ‘context’ [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:171: error: making ‘co ntext’ static [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:171: error: invalid in -class initialization of static data member of non-integral type ‘GPContext*’
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:177: error: ISO C++ fo rbids initialization of member ‘camera’ [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:177: error: making ‘ca mera’ static [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:177: error: invalid in -class initialization of static data member of non-integral type ‘Camera*’
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:181: error: ISO C++ fo rbids initialization of member ‘rootWidget’ [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:181: error: making ‘ro otWidget’ static [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:181: error: invalid in -class initialization of static data member of non-integral type ‘CameraWidget*’
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:213: error: ISO C++ fo rbids initialization of member ‘abilitiesList’ [-fpermissive]
    /opt/opencv/opencv310/modules/videoio/src/cap_gphoto2.cpp:213: error: making ‘ab ilitiesList’ static [-fpermissive]

    • What is your GCC/g++ version?

      • Linux version 2.6.32-279.el6.x86_64 (mockbuild@x86-008.build.bos.redhat.com)
        (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Wed Jun 13 18:24:36 EDT 2012

        • Your Linux kernel is pretty old…I guess you are on a virtual machine or something…please run the following command and let me know the result:
          g++ --version

          I can already tell your gcc/g++ is quite old. you need to have a much more recent version e.g. 4.8 or up. Also make sure you have installed all the required packages

          • Thank you!the result is:
            g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)

            Version is very old.I don’t know what are all the required packages, can you list?Thanks!

          • I changed a version, but the Linux kernel is also very old.So I want to know what are all the required packages.Thank you!

          • You need GCC 4.8 or higher. Required packages were listed in the article, again:

            sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

  9. Dear Saeid,

    Thank you very much for the awesome tutorial. I was able to compile Opencv-3.1.0 without any error following your tutorial. And I tested the opencv with some basic functions without using Gpu, it was working well. However, when I tried to use some Gpu functions (compiled successfully), I got the following running ERRORS:

    OpenCV Error: Gpu API call (unknown error) in allocate, file /home/jiang/CvLibs/opencv/modules/core/src/cuda/gpu_mat.cu, line 71
    Error: /home/jiang/CvLibs/opencv/modules/core/src/cuda/gpu_mat.cu:71: error: (-217) unknown error in function allocate

    Here is my code:
    int main(int argc, const char* argv[])
    {
    try
    {
    cv::Mat src_host = cv::imread("../data/basketball1.png", cv::IMREAD_GRAYSCALE);
    cv::cuda::GpuMat dst, src;
    src.upload(src_host);
    cv::cuda::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);
    cv::Mat result_host(dst);
    cv::imshow("Result", result_host);
    cv::waitKey();
    }
    catch(const cv::Exception& ex)
    {
    std::cout << "Error: " << ex.what() << std::endl;
    }

    return 0;
    }

    Thank you very much and look forward to your reply!
    Cansen

    • Seems that you are trying to do some CUDA…apart from having a correct installation of CUDA and NVCC compiler…the method in my article does not build for cuda…you have to build opencv again with cuda enabled…you need to do from this step:


      cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 ..

      again ….double dot in the end should be replaced with the opencv source directory

      • First Thanks for the blog, after i have a trouble after compile this is the message:
        [ 2%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
        /usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
        /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
        return (char *) memcpy (__dest, __src, __n) + __n;
        ^
        CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
        Error generating file
        /home/xavysp/opencv-3.1.0/release/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

        Could you help me with advice,

        Best regards,

        Xavier

        Ohh I am working on ubuntu 16.04

        • Add this line in the front of the CMakeLists.txt

          set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D_FORCE_INLINES”)

          It worked for me!!!

  10. I can not configure, it shows that message:

    Configuring incomplete, errors occurred!

    There is the CMakeError.log:

    ——————————————————————————
    Determining if the system is big endian passed with the following output:
    Change Dir: /home/kauevestena/opt/opencv/release/CMakeFiles/CMakeTmp

    CMakeFiles/cmTryCompileExec3960062789.dir/CheckIncludeFile.c.o -c /home/kauevestena/opt/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c
    /home/kauevestena/opt/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:29: fatal error: ffmpeg/avformat.h: No such file or directory
    #include
    ^
    compilation terminated.
    make[1]: *** [CMakeFiles/cmTryCompileExec3960062789.dir/CheckIncludeFile.c.o] Error 1
    make[1]: Leaving directory `/home/kauevestena/opt/opencv/release/CMakeFiles/CMakeTmp’
    make: *** [cmTryCompileExec3960062789/fast] Error 2

    ——————————————————————————

    I should reinstall ffmpeg lib?

    • You have many errors! I dont know where to start…but make sure you have a recent version of GCC (e.g. 4.8 and higher), you have CMAKE version 3 or higher, you have installed the required packages as I said in the article (e.g. libavcodec-dev libavformat-dev libswscale-dev) and yes you need to install ffmpeg if you want opencv to work with video files/inputs.

  11. That worked.
    Thank you!
    Success!

  12. During Make and install, I get the following error after the first command (make):

    make: *** No targets specified and no makefile found. Stop.

    then after the second command (sudo make install):
    make: *** No rule to make target `install’. Stop.

    What did I do wrong, and how can I fix this?

    • On closer inspection: on the last command of the pre-build configuration I have an error. by looking in the error log I see the following “fatal errors”:

      1)
      /home/icey/opt/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:25: fatal error: sys/videoio.h: No such file or directory

      2)
      /home/icey/opt/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:29: fatal error: ffmpeg/avformat.h: No such file or directory

      3)
      /home/icey/opt/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:28: fatal error: linux/videodev.h: No such file or directory

      • Either this:
        You did not install required packages (libav…) please look to the article again.
        Also install ffmpeg

        or this:
        I think you did not respect the double dots “..” at the end of cmake command! that tells cmake to find source files from a directory above. You can replace this double dots with a fixed path e.g. /path/to/your/sourcefiles

      • I am having same error above. Is there anyone could fix it?

    • Fix missing linux/videodev.h:
      ln -s /usr/include/libv4l1-videadev.h /usr/include/linux/videodev.h

      Fix missing ffmpeg/avformat.h:
      mkdir /usr/include/ffmpeg && \
      sudo ln -sf /usr/include/libavcodec/*.h /usr/include/ffmpeg && \
      sudo ln -sf /usr/include/libavformat/*.h /usr/include/ffmpeg && \
      sudo ln -sf /usr/include/libswscale/*.h /usr/include/ffmpeg && \

      Still searching for a fix for missing sys/videoio.h, anyone?

      • Thats file is part of ‘libv4l-dev’ package. Have you installed that? I am also not sure if it should be inside /sys fodler!! should be rather /usr/include or something like that.

  13. extremely useful bro.
    thanks a lot

  14. Pingback: Raspberry Pi | David Albert

  15. Pingback: JavaCV (OpenCV for Java) on Raspberry Pi | David Albert

  16. Great tutorial, you saved a lot of my time 🙂

  17. Mark Stevens

    Hi,

    I’ve tried to install OpenCV on Debian for the past two days and hit the same errors. I followed your guide to the letter and have this output from make:

    [ 33%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/opencl_kernels_imgproc.cpp.o
    Linking CXX shared library ../../lib/libopencv_imgproc.so
    [ 33%] Built target opencv_imgproc
    Makefile:147: recipe for target 'all' failed
    make: *** [all] Error 2

    Any help?

  18. vincentweisen

    Thanks for your tutorial. I follow every step in your article, but I’m getting some error in “make” command:

    In file included from /usr/include/hdf5.h:27:0,
    from /home/vincentee/opencv_contrib/modules/hdf/include/opencv2/hdf/hdf5.hpp:40,
    from /home/vincentee/opencv_contrib/modules/hdf/include/opencv2/hdf.hpp:38,
    from /home/vincentee/opencv/release/modules/hdf/precomp.hpp:42:
    /usr/include/H5Dpublic.h:145:14: note: declared here
    H5_DLL hid_t H5Dopen1(hid_t file_id, const char *name);
    ^
    make[2]: *** [modules/hdf/CMakeFiles/opencv_hdf.dir/src/hdf5.cpp.o] Error 1
    make[1]: *** [modules/hdf/CMakeFiles/opencv_hdf.dir/all] Error 2
    make: *** [all] Error 2

    However, I check my hdf5 library using dpkg -l | grep hdf5, it is 1.8.4 version:

    ii libhdf5-mpich-1.8.4 1.8.4-patch1-3ubuntu2 Hierarchical Data Format 5 (HDF5) – runtime files – MPICH version
    ii libhdf5-mpich-dev 1.8.4-patch1-3ubuntu2 Hierarchical Data Format 5 (HDF5) – development files – MPICH version
    rc libhdf5-serial-1.8.4

    I’m using ubuntu 12.04 system, my gcc/g++ version is 4.8.1, Linux kernel version is 3.13.0-32-generic. Do you know how to solve it?

  19. Pingback: Opencv 3.1 installation note – vincentweisen

  20. Hi! Thanks for the tutorial. I followed the instructions and have installed opencv 3.1.0. But when I run a test program, which should read and show an image using imread() and imshow(), it turned out that imread() always returns a empty matrix. I have checked the directory of the image and it remains the same even with absolute directory. I also tried building either debug and release version of the program and it didn’t work… Any idea what may be wrong?

  21. Ashim Batajoo

    I have all the packages to the latest version.
    But still i get ” Configuring incomplete, errors occurred!” while configuring.
    gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413

    cmake is already the newest version (3.5.1-1ubuntu1).
    git is already the newest version (1:2.7.4-0ubuntu1).
    libgtk2.0-dev is already the newest version (2.24.30-1ubuntu1).
    pkg-config is already the newest version (0.29.1-0ubuntu1).
    libavcodec-dev is already the newest version (7:2.8.6-1ubuntu2).
    libavformat-dev is already the newest version (7:2.8.6-1ubuntu2).
    libswscale-dev is already the newest version (7:2.8.6-1ubuntu2)

    Trying on ubuntu 16.0.4LTS

  22. How to solve this?
    — Install path: /usr/local

    — cvconfig.h is in: /home/foong/opencv/release
    — —————————————————————–

    — Configuring incomplete, errors occurred!
    See also “/home/foong/opencv/release/CMakeFiles/CMakeOutput.log”.
    See also “/home/foong/opencv/release/CMakeFiles/CMakeError.log”.

  23. Hey, I get the same errors as everybody:

    -Configuring incomplete, errors occurred!
    -See also “/home/foong/opencv/release/CMakeFiles/CMakeOutput.log”.
    -See also “/home/foong/opencv/release/CMakeFiles/CMakeError.log”.

    I don’t know what’s happening but I don’t think it is the directory, because I tried with other version (3.0.0) also using the 3.00 opencv_contrib, and with this tutorial ” http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/ “, also writting down the extra line “-D OPENCV_EXTRA_MODULES_PATH=/OpenCV/opencv_contrib-3.0.0/modules” for the release folder or also named build in that tutorial, and it works completely, with your tutorial I couldn’t do anything :/

    • If your tutorial works for you, please tell us the EXACTLY WAY you get it to work in your computer with screenshots, because I can’t believe this way and most in the internet works, because of that bunch of errors with most OpenCV versions when using linux, also I gotta say there are a lot of files that cmake doesn’t found when building, I don’t know why, and it happens with ALL the tutorials I have searched about this!

      If you want to try, and make a better, working tutorial I can tell you these of my description:

      “OpenCV” folder is your “opt/” folder, and it’s at “Home” I mean your first user directory (/home/(your_User)/OpenCV), inside that one there are the folders:

      “opencv_contrib-3.0.0”
      https://codeload.github.com/Itseez/opencv_contrib/zip/3.0.0

      “opencv-3.0.0-alpha”
      https://codeload.github.com/Itseez/opencv/zip/3.0.0-alpha

      • I am just amazed why people are not willing to make some effort of copy pasting the error messages on google and get more info over it. In my video you can see what exactly I did.

  24. I found this post while looking up an error that happens when I try to run make command. OpenCV compiles about 43% of the way before encountering an error making the libopencv_videoio.so.3.1.0 file, apparently because it has no rule to make the required libavcodec.a . I know I have libavcodec-dev installed, along with the other required packages mentioned in this post, so I’m a bit lost as to why it doesn’t succeed. One possible explanation I’ve thought of is that the Ubuntu 15.04 system I’m using right now doesn’t have a built in camera, so perhaps cmake skipped over making a rule because it couldn’t detect any video I/O hardware, not realizing this is still needed.

    Unfortunately I’m not familiar enough with make or cmake to know how to rectify this except to try taking the libopencv_videoio.so.3.1.0 from a pre-built OpenCV project. Below is the error message I get. Perhaps someone else has more experience to know how to get past this properly.

    make[2]: *** No rule to make target ‘/usr/include/../lib/libavcodec.a’, needed by ‘lib/libopencv_videoio.so.3.1.0’. Stop.
    CMakeFiles/Makefile2:6038: recipe for target ‘modules/videoio/CMakeFiles/opencv_videoio.dir/all’ failed
    make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs….
    [ 43%] [ 43%] Built target opencv_dnn
    Makefile:147: recipe for target ‘all’ failed
    make: *** [all] Error 2

    • you also need to have ffmpeg packages make sure to install the dev package of the missing library.After installing that package you better start compiling again, after make clean and resetting the cmake cache.

      I don’t think the error has anything to do with not having a camera.

  25. robot3@robot3:/opt$ sudo git clone https://github.com/Itseez/opencv.git
    Cloning into ‘opencv’…
    fatal: unable to access ‘https://github.com/Itseez/opencv.git/’: Failed to connect to github.com port 443: Connection timed out

  26. I do not know what happened. Following to your post, I typed: sudo apt-get remove libopencv*. After doing this, everything got uninstalled: gazebo, rviz, my husky package and other packages installed with Sudo.

    Please help me how can I retrieve those packages?

    • Sorry for inconvenience you experienced. That command does not remove all packages of course, rather the packages that have something to do with opencv. The only way to bring them back is to install them again 🙁

  27. Hi,

    I got and installed OpenCV3.1.0 at http://opencv.org/downloads.html for Win7, VS2010. It run well with my application.

    However, when I tried to install contributed modules and OpenCV3.1.0, install openCV3.1 and contribution modules are no problem, but running the same previous application has problem. When I run my application with installed contributed modules, the message error:

    Unhandled exception at 0x000007fee423903f (opencv_imgproc310d.dll)

    I used cmake-3.5.1 with options:
    – With CUDA: On
    – With OpenGL: On
    – With SSE2, SSE3: On
    – With AVX, AVX2: On
    – With Matlab: off

    I tried install several times, it is still error.

    Could you please tell me what is problem?

    Thank you very much!

    • I have no experience with OpenCV on windows. But I think the error you get means that the opencv_imgproc310d.dll is compiled with a different compiler than the compiler you are trying to compile your application with.

      • Thank you for your reply.

        I solved my problem. In my case, I put contributed modules inside modules folder of OpenCV3.1.0 source and AVX, AVX2: off, and then build with CMake. I don’t know why it works 😀

        Anyway, the problem is solved.

  28. Thank you for the tutorial however during the “make” i have the following error:

    ….
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to TIFFTileSize@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to
    _TIFFmalloc@LIBTIFF_4.0′
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to TIFFSetErrorHandler@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to
    TIFFSetDirectory@LIBTIFF_4.0′
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to TIFFReadScanline@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to
    TIFFClose@LIBTIFF_4.0′
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to TIFFNumberOfTiles@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to
    TIFFClientOpen@LIBTIFF_4.0′
    collect2: error: ld returned 1 exit status
    modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:232: recipe for target ‘bin/opencv_test_viz’ failed
    make[2]: *** [bin/opencv_test_viz] Error 1
    CMakeFiles/Makefile2:4780: recipe for target ‘modules/viz/CMakeFiles/opencv_test_viz.dir/all’ failed
    make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
    Makefile:160: recipe for target ‘all’ failed
    make: *** [all] Error 2

    any suggestion ?

    Thank you in advance

  29. Saurabh Varshneya

    Hello,

    This was really helpful to me. It worked like charm. When are you going to upload tut on using OpenCV in conjunction with QtQuick on Linux! waiting for it….

  30. On Ubuntu Xenial (16.04 LTS), it seems that libgstreamer-plugins-base1.0-dev needs to be installed as well in order for the compilation to succeed.

  31. Also this could be useful for people (like me) running into the HDF5 compiling error: https://github.com/Itseez/opencv/issues/6016

  32. Thanks for your help! But running into an issue with the make command.
    Ubuntu version: 12.04
    gcc version 4.8.
    “[27%] Built target IlmImf
    CMake Error: Cannot open file for write: /opt/opencv/release/modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/depend.make.tmp”
    I tried to chmod /opt/opencv, that wasn’t the problem. Any suggestions? Thanks!

    • That could be a CMake specific error…did you try to run the command with sudo to see if it helps? whats your cmake version? I recommend 3.2+ or even 3.5.2 you can read the install guide in another article in my website.

      • That fixed that problem, thank you! The terminal is now saying /opt/opencv/release/modules/hdf/precomp.hpp.gch/opencv_hdf_RELEASE.gsh is not compatible with this GCC version. My cmake is 2.8.7. I did sudo apt-get upgrade, but that upgraded everything other than cmake basically. Can I follow your tutorial to upgrade cmake when it’s already downloaded? Or do I have to uninstall the current version. I looked into doing that previously, but it looked like a lot of ros packages would be removed so I didn’t.

        • If you follow my guide for building cmake at the end just before installing it you can see the compiled executables and libs in the folder. You can use it as standalone.

          • hi. thanks for the tutorial. but i`m having problem when i follow the cmake step.
            /opt/opencv/release$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib/modules /opt/opencv/
            CMake Error: The source directory “/opt/opencv” does not exist.

          • just have a closer look to the error message: the last “/opt/opencv”in the cmake command is the place where your source code of opencv should be! is your opencv source code exist in that directory!?

        • Removing your old cmake might remove some dependency packages but its fine at worst case you install them again. Just take a note from things that are going to be removed.

          • Okay I removed my 2.8 version and followed your tutorial step by step. When I run cmake –version now it says “bash: /usr/bin/cmake: No such file or directory” but when I ran cmake-gui, that popped up, so I ignored the error. But then when I went back to the /opt/opencv/release folder to run make, the same error “make: /usr/bin/cmake: Command not found” happened. Do I need to move something to my /usr/bin to fix this? Thanks for your help!

          • You can make a symbolic link to the cmake 3.5.2 bin file in the /usr/bin folder. That should take care of the problem.

  33. make: *** No rule to make target `install’. Stop. << i got this message at the last step

    And, how do i compile the program? can i use ./build.sh like I did in OpenCV 2.4.9? Thx 🙂

  34. thx a lot!

  35. hi i have some problem in installing
    [ 22%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/jpeg_exif.cpp.o
    make[2]: *** No rule to make target /usr/lib/libpng.so', needed by lib/libopencv_imgcodecs.so.3.1.0′. Stop.
    make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
    make: *** [all] Error 2
    thx for your help 😀

  36. i followed the steps
    but i got error in the ‘cmake’ step
    Configuring incomplete, errors occurred!
    See also “/home/ubuntu/imginfo_reader/opencv/opencv/release/CMakeFiles/CMakeOutput.log”.
    See also “/home/ubuntu/imginfo_reader/opencv/opencv/release/CMakeFiles/CMakeError.log”.

    please help

    • So what does the log file says? what is the actual error? paste your log into pastebin.com and put the link here.

      • Abdul Rehman
        Determining if the system is big endian passed with the following output:
        Change Dir: /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp

        Run Build Command:"/usr/bin/make" "cmTC_947a6/fast"
        /usr/bin/make -f CMakeFiles/cmTC_947a6.dir/build.make CMakeFiles/cmTC_947a6.dir/build
        make[1]: Entering directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_947a6.dir/TestEndianess.c.o
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -o CMakeFiles/cmTC_947a6.dir/TestEndianess.c.o -c /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/TestEndianess.c
        Linking C executable cmTC_947a6
        /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_947a6.dir/link.txt --verbose=1
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG CMakeFiles/cmTC_947a6.dir/TestEndianess.c.o -o cmTC_947a6 -rdynamic
        make[1]: Leaving directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'

        TestEndianess.c:
        /* A 16 bit integer is required. */
        typedef unsigned short cmakeint16;

        /* On a little endian machine, these 16bit ints will give "THIS IS LITTLE ENDIAN."
        On a big endian machine the characters will be exchanged pairwise. */
        const cmakeint16 info_little[] = {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000};

        /* on a big endian machine, these 16bit ints will give "THIS IS BIG ENDIAN."
        On a little endian machine the characters will be exchanged pairwise. */
        const cmakeint16 info_big[] = {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000};

        #ifdef __CLASSIC_C__
        int main(argc, argv) int argc; char *argv[];
        #else
        int main(int argc, char *argv[])
        #endif
        {
        int require = 0;
        require += info_little[argc];
        require += info_big[argc];
        (void)argv;
        return require;
        }

        Determining if the include file /home/shahid/anaconda3/include/libpng/png.h exists failed with the following output:
        Change Dir: /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp

        Run Build Command:"/usr/bin/make" "cmTC_874ac/fast"
        /usr/bin/make -f CMakeFiles/cmTC_874ac.dir/build.make CMakeFiles/cmTC_874ac.dir/build
        make[1]: Entering directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_874ac.dir/CheckIncludeFile.c.o
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -o CMakeFiles/cmTC_874ac.dir/CheckIncludeFile.c.o -c /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c
        /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:55: fatal error: /home/shahid/anaconda3/include/libpng/png.h: No such file or directory
        compilation terminated.
        CMakeFiles/cmTC_874ac.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_874ac.dir/CheckIncludeFile.c.o' failed
        make[1]: *** [CMakeFiles/cmTC_874ac.dir/CheckIncludeFile.c.o] Error 1
        make[1]: Leaving directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Makefile:126: recipe for target 'cmTC_874ac/fast' failed
        make: *** [cmTC_874ac/fast] Error 2

        Determining if the include file linux/videodev.h exists failed with the following output:
        Change Dir: /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp

        Run Build Command:"/usr/bin/make" "cmTC_5e10a/fast"
        /usr/bin/make -f CMakeFiles/cmTC_5e10a.dir/build.make CMakeFiles/cmTC_5e10a.dir/build
        make[1]: Entering directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_5e10a.dir/CheckIncludeFile.c.o
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -o CMakeFiles/cmTC_5e10a.dir/CheckIncludeFile.c.o -c /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c
        /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:28: fatal error: linux/videodev.h: No such file or directory
        compilation terminated.
        CMakeFiles/cmTC_5e10a.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_5e10a.dir/CheckIncludeFile.c.o' failed
        make[1]: *** [CMakeFiles/cmTC_5e10a.dir/CheckIncludeFile.c.o] Error 1
        make[1]: Leaving directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Makefile:126: recipe for target 'cmTC_5e10a/fast' failed
        make: *** [cmTC_5e10a/fast] Error 2

        Determining if the include file sys/videoio.h exists failed with the following output:
        Change Dir: /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp

        Run Build Command:"/usr/bin/make" "cmTC_5656e/fast"
        /usr/bin/make -f CMakeFiles/cmTC_5656e.dir/build.make CMakeFiles/cmTC_5656e.dir/build
        make[1]: Entering directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_5656e.dir/CheckIncludeFile.c.o
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -o CMakeFiles/cmTC_5656e.dir/CheckIncludeFile.c.o -c /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c
        /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:25: fatal error: sys/videoio.h: No such file or directory
        compilation terminated.
        CMakeFiles/cmTC_5656e.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_5656e.dir/CheckIncludeFile.c.o' failed
        make[1]: *** [CMakeFiles/cmTC_5656e.dir/CheckIncludeFile.c.o] Error 1
        make[1]: Leaving directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Makefile:126: recipe for target 'cmTC_5656e/fast' failed
        make: *** [cmTC_5656e/fast] Error 2

        Determining if the include file ffmpeg/avformat.h exists failed with the following output:
        Change Dir: /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp

        Run Build Command:"/usr/bin/make" "cmTC_0654b/fast"
        /usr/bin/make -f CMakeFiles/cmTC_0654b.dir/build.make CMakeFiles/cmTC_0654b.dir/build
        make[1]: Entering directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_0654b.dir/CheckIncludeFile.c.o
        /usr/bin/cc -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 -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -o CMakeFiles/cmTC_0654b.dir/CheckIncludeFile.c.o -c /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c
        /home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:29: fatal error: ffmpeg/avformat.h: No such file or directory
        compilation terminated.
        CMakeFiles/cmTC_0654b.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_0654b.dir/CheckIncludeFile.c.o' failed
        make[1]: *** [CMakeFiles/cmTC_0654b.dir/CheckIncludeFile.c.o] Error 1
        make[1]: Leaving directory '/home/shahid/cv/opencv/release/CMakeFiles/CMakeTmp'
        Makefile:126: recipe for target 'cmTC_0654b/fast' failed
        make: *** [cmTC_0654b/fast] Error 2

    • Abdul Rehman

      i m also facing this problem if you done it please tell me
      thanks

  37. great walkthrough. One point though. I had CUDA installed on my system and I think by default cmake compiles for CUDA. This is good in the long run for very intensive computations but can take several hours in make. So one might want exclude building for CUDA support by using this flag in their cmake command -D WITH_CUDA=OFF source: https://codeyarns.com/2013/07/23/how-to-compile-opencv-without-cuda-support/

  38. Sir, i’d followed all the instruction without error but when run make command i always got this problem:

    root@kali:/opt/opencv/release# make
    [ 0%] Built target opencv_core_pch_dephelp
    [ 0%] Built target opencv_test_core_pch_dephelp
    [ 0%] Generating precomp.hpp.gch/opencv_core_RELEASE.gch
    In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
    from /usr/include/c++/6/algorithm:62,
    from /opt/opencv/modules/core/include/opencv2/core/base.hpp:53,
    from /opt/opencv/modules/core/include/opencv2/core.hpp:54,
    from /opt/opencv/modules/core/include/opencv2/core/utility.hpp:52,
    from /opt/opencv/release/modules/core/precomp.hpp:49:
    /usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
    #include_next
    ^
    compilation terminated.
    modules/core/CMakeFiles/pch_Generate_opencv_core.dir/build.make:62: recipe for target 'modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch' failed
    make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch] Error 1
    CMakeFiles/Makefile2:1887: recipe for target 'modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all' failed
    make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2
    Makefile:160: recipe for target 'all' failed
    make: *** [all] Error 2

    What should i do? Please help, thanks.

    • I finally solved the problem.
      I just added: -D ENABLE_PRECOMPILED_HEADERS=OFF to cmake command, it works for me until 95% then the another problem is about fatal error: hdf5.h: No such file or directory
      I solved it by adding:

      find_package(HDF5)
      include_directories(${HDF5_INCLUDE_DIRS})

      into modules/python/common.cmake
      (I just put it at the bottom)

      rerun make again i got 100% success compilation.

    • stdlib.h not found…is a very primitive error….you need to install required packages I named in the beginning of the article…namely build-essential and libstd

      • libstdc++-5-dev is already the newest version (5.4.1-3).
        libstdc++-5-dev set to manually installed.
        libstdc++-6-dev is already the newest version (6.2.0-9).
        libstdc++-6-dev set to manually installed.
        libstdc++6 is already the newest version (6.2.0-9).

        this is the output when i tried to install, is it right sir?

  39. Hi, Thanks for the article. When I do “make”, it goes until 8% and I get the following error on ubuntu 16.04:
    I don’t have gpu.
    Any clues??

    thanks in advance.
    —————————————————————————————————————–
    [ 8%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
    /usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
    /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
    return (char *) memcpy (__dest, __src, __n) + __n;
    ^
    CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
    Error generating file
    /home/snoopy/opencv-3.1.0/release/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

    modules/core/CMakeFiles/opencv_core.dir/build.make:399: recipe for target ‘modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o’ failed
    make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o] Error 1
    CMakeFiles/Makefile2:2166: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/all’ failed
    make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
    Makefile:160: recipe for target ‘all’ failed
    make: *** [all] Error 2
    —————————————————————————————————————

    • You have to disable cuda support, its best to open cmaketext file with cmake-gui and look for that option and disable it.

      • Thanks Saeid, D here. I disabled cuda support. however, a similar error still remained, but after few other changes, now it works!!!!!!!!

  40. Hey thanks. I screwed around for a couple hours trying to get opencv3.1 installed on ubuntu14.04 then found this post. worked the first time.

  41. Mehdi Sajjadi

    hi

    Appreciate your help and useful guide for Opencv installation.
    I want to install OpenCv on my Raspberry board for image processing, I am doing exactly as you mentioned, but whenever I am running the “Pre-buld Configuration” After running cmake command I am receiving an error as comes in following:

    Configuring incomplete, errors occurred!
    See also “/home/pi/opt/opencv/release/CMakeFiles/CMakeOutput.log”.
    See also “/home/pi/opt/opencv/release/CMakeFiles/CMakeError.log”.

    Would you please let me know how I can eliminate this error?
    Also I am running the command that is mentioned OpenCv website and seems it is working but when I am running program in Gcc,I cannot define “Mat” vector for storing image in it.

    I appreciate if you help and advice on this matter.

    Regards

    Mehdi

    • That’s a critical error, meaning you have not downloaded sources completely, or you are pointing to wrong folder of sources when trying to run cmake. If you follow the guide correctly, there should be no reason for that error to happen.

  42. Vignesh Kumar

    hahahahahah

  43. I am facing same kind of problem. Whenever I try to install OpenCV it halts at 37%. The error is given below

    collect2: error: ld returned 1 exit status
    apps/visualisation/CMakeFiles/opencv_visualisation.dir/build.make:104: recipe for target ‘bin/opencv_visualisation’ failed
    make[2]: *** [bin/opencv_visualisation] Error 1
    CMakeFiles/Makefile2:7461: recipe for target ‘apps/visualisation/CMakeFiles/opencv_visualisation.dir/all’ failed
    make[1]: *** [apps/visualisation/CMakeFiles/opencv_visualisation.dir/all] Error 2
    Makefile:149: recipe for target ‘all’ failed
    make: *** [all] Error 2

    Also it gives error for file named libpq.so

  44. Hey Saeid,
    I too have problems with cmake:
    — Configuring incomplete, errors occurred!
    See also “/opt/opencv/release/CMakeFiles/CMakeOutput.log”.
    See also “/opt/opencv/release/CMakeFiles/CMakeError.log”.

    The contents of CMakeError.log can be found here:
    http://pastebin.com/bxUJT6gc

    Where do all these invalid command line options come from?
    I’m on Ubuntu 14.04, gcc/g++ 4.9.4 and cmake 3.2.2

    Thanks for the tutorial!

  45. Saeid,
    I found the issue. opencv_contrib was in the wrong place…
    Sorry for the double post

  46. Hi Saeid! I tried using your method exactly, but i got these errors:

    Linking CXX shared library ../../lib/libopencv_videoio.so
    /usr/bin/ld: /usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `ff_a64_muxer’ can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libavformat.a: error adding symbols: Bad value
    collect2: error: ld returned 1 exit status
    make[2]: *** [lib/libopencv_videoio.so.3.3.0] Error 1
    make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
    make: *** [all] Error 2

    I searched Google for a solution but came up short. I am pretty new to OpenCV. Do you think you could help?

  47. Aldo Camargo

    Thanks a lot for the post and all the information.

    I am getting this error:
    [100%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
    In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:4:0,
    from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:18,
    from /opt/opencv/modules/python/src2/cv2.cpp:10:
    /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_common.h:17:5: warning: “NPY_INTERNAL_BUILD” is not defined [-Wundef]
    #if NPY_INTERNAL_BUILD
    ^
    In file included from /opt/opencv_contrib/modules/tracking/include/opencv2/tracking/tracker.hpp:48:0,
    from /opt/opencv/release/modules/python2/pyopencv_generated_include.h:50,
    from /opt/opencv/modules/python/src2/cv2.cpp:12:
    /opt/opencv_contrib/modules/tracking/include/opencv2/tracking/onlineMIL.hpp:57:23: error: expected unqualified-id before ‘>’ token
    #define sign(s) ((s > 0 ) ? 1 : ((s<0) ? -1 : 0))

  48. Hi,
    i installed a package which one of its dependencies is opencv, so opencv3.4.2 is installed bay bash, but in compile time i got the error:
    cannot find videoio.h

    as i surfed i got your page, so would you please help me to find out how to fix it true?
    Thanks in advance,

  49. hi, can you help me for two questions about installing opencv:
    1. how to set the OpenCV libraries “Path” as “/usr/lib/”?
    2. how to set the OpenCV header files. “Path” as “/usr/include/opencv”?

Leave a Reply

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.