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.


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!


  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/', necessário por lib/′. 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/
        chmod: impossível operar sobre ligação simbólica «/usr/lib/»

  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 ..

            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

  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 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 (
        (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/, line 71
    Error: /home/jiang/CvLibs/opencv/modules/core/src/cuda/ error: (-217) unknown error in function allocate

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

    return 0;

    Thank you very much and look forward to your reply!

    • 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:


      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/
        /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 (message):
        Error generating file

        Could you help me with advice,

        Best regards,


        Ohh I am working on ubuntu 16.04

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


          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
    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!

  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”:

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

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

      /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


    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/
    [ 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 ” “, 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:



      • 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 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 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/’. 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
    Cloning into ‘opencv’…
    fatal: unable to access ‘’: Failed to connect to 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 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/ undefined reference to TIFFTileSize@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/ undefined reference to
    //usr/lib/x86_64-linux-gnu/ undefined reference to TIFFSetErrorHandler@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/ undefined reference to
    //usr/lib/x86_64-linux-gnu/ undefined reference to TIFFReadScanline@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/ undefined reference to
    //usr/lib/x86_64-linux-gnu/ undefined reference to TIFFNumberOfTiles@LIBTIFF_4.0'
    //usr/lib/x86_64-linux-gnu/ undefined reference to
    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


    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:

  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 ./ 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/', needed by lib/′. 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

  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:

Leave a Reply

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