How to build OpenCV from source for VC14

Posted on Posted in OpenCV Tutorials, Qt Tutorials, Tutorials

OpenCV 2.4.11 users may have noticed that it does not provide pre-built binaries (Libs and DLLs) for VC14 (Visual Studio 2015) Unfortunately it is also the case with Qt 5.5.1 (At least it’s true at the time of writing this article) so if you are going to use either one of them you have to build it yourself.

I was also faced with this obstacle so I decided to write a guide for anyone who wishes to built OpenCV for VC14.To do that, just follow the steps below:

Requirements:

OpenCV source codes

CMake

Visual Studio 2015 Community

Note 1: This guide is already tested with CMake 3.4.1, OpenCV 2.4.11 and Visual Studio 2015 but there is a very high chance that it would work with later versions too, but I’m not sure about previous versions, you have to test it for yourself.

Note 2: You are not required to use the same folders. You may extract OpenCV sources somewhere different and also install the binaries to another place but throughout my guide and in the pictures you’ll see the same paths.

So, here it is.

  • First run CMake and set the required folders.
    • Source codes are in the existing folder that can be found inside OpenCV folder after its installation
    • The second folder you see below is the one that will be created during the build.

 

2015-12-04 (2)





  • Click yes after you are warned with the message shown below.

2015-12-04 (3)

  • Now click configure. Then select “Visual Studio 14 2015” from the list. Note that you can also select WIN64 for a 64 build but in this guide I am creating a x86 build.

2015-12-04 (4)

  • Wait for the process to finish.

2015-12-04 (6)

  • Do not change any settings at this stage, just click on Generate.

2015-12-04 (12)





  • After generate is finished, close CMake and run Visual Studio Community 2015. Then open “OpenCV.SLN” file from the build directory.

2015-12-04 (18)

  • After the solution is opened, just right click on the solution’s name and Rebuild.

2015-12-04 (19)

  • After building for Debug mode ends change the build type to release, then right click and run Rebuild again.

2015-12-04 (22)

  • This concludes this tutorial. You have built all required libraries for OpenCV to use with Visual Studio 2015 (Visual C++ 2015) or Visual C++ 14.0. You can find the LIB and DLL files in separate folders. Debug and Release build folders are also created inside them.

2015-12-04 (24)





If you have any questions just put a comment below.

24 thoughts on “How to build OpenCV from source for VC14

  1. opencv 2.4.12 cmake 3.5.1 error message.

    Severity Code Description Project File Line Suppression State
    Error C2610 ‘std::tuple::tuple(const std::tuple &)’: is not a special member function which can be defaulted opencv_perf_gpu C:Program Files (x86)Microsoft Visual Studio 14.0VCincludetuple 328

    1. Please let me know what parameters you are using to build OpenCV. Most probably you are using a parameter which has dependencies that are not met on your system. I suggest going for only the ones that you need and you are sure that have dependencies on your computer.

  2. Hi Amin, Thanks for this tutorial. I was stuck for a while till I followed the instructions. However, I ran into a small problem right towards the end when rebuilding with VS 2015.

    Everytime I tried to rebuild, the process crashes my computer. I recall seeing errors about “cryptoAPI” during the build just before the crash, but it was too fast to capture the entire error. Is there an error log I can retrieve and what might be the problem? It’s the same with rebuilding the debug and release, except the crash happens much earlier during release.

    Could you advise? Thank you so much.

  3. Hi Amin, Thanks for your tutorial which helped me a lot. However, I am facing a problem where VS crashes during the rebuild of both the debug and release builds. The last words I could catch on the process window was about error with “cryptoAPI”.

    Is there an error logfile I can access and what do you think might be the problem?

    Thanks.

    Michael

    1. Hi Michael,
      Which OpenCV version you are using?
      Are you trying a build mixed with something else? Or might be there is some kind of conflict between folders?!

      To be honest I have never faced such an error and to me it doesn’t seem to be related to OpenCV.

      1. Hi,

        Thanks for the reply. I managed to solve the problem. Seems like it may have been a faulty install of VS 2015, specifically the build tools. I reinstalled it and the problem is gone. 🙂

  4. Done these process. So If i run any projects it will automatically show me the librariers or what?

    1. Not sure what you mean exactly. But if you mean libraries will be automatically added to your project, no that won’t happen. You have to set all of them manually. Did I get it right? 🙂

  5. Q1:
    Is that ok with fail item after building for Debug and Release mode? I also see the fail item in your photo.

    Q2:
    If I do not change any settings at this stage, just click on Generate.

    is the result fit my environment? ex: if I don’t have GPU but I didn’t mark out the option

    1. A1: You can’t continue if it fails. The message you see in the picture is just a safe warning. You can always continue building if you pay attention to warnings and messages.

      A2: You can just click generate. Just note that if there are missing headers for any of the options, it might fail. And, you can build with any options you want and use with some other options.

      I suggest playing around with different options if you are trying to learn and not in a hurry. There are priceless lessons in it.

  6. Thank you for your tutorial. I met a error in configuration process, project files may be invalid. Can you suggest to solve this problem?

    1. Make sure you select the correct generator during the configuration. If you still face the same problem then please try to share more info about how you are trying to configure and build so that I can help you with the process.

  7. hello Dear Amin
    i cant speak english very well but i hava a problem about opencv !
    i wrote my first program in VS 2015 to learn opencv by code :

    #include
    #include
    using namespace cv;
    using namespace std;

    int main() {

    Mat im = imread(“cameraman.tiff”, 0);
    if (im.empty()) {

    cout << "Can not load image !" <—— Build started: Project: Project1, Configuration: Debug Win32 ——
    1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.
    1> Opncv.cpp
    1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\crtdefs.h(10): fatal error C1083: Cannot open include file: ‘corecrt.h’: No such file or directory
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    please help me if you can !

    im using visual studio 2015 update 1 ( a 32bit version i think) and open cv 3.1.0 (a 64bit version).
    do you think that the problem is incompatibility between these ?
    my windows is also 7 64bit service pack 1

    1. #include
      #include
      using namespace cv;
      using namespace std;

      int main() {

      Mat im = imread(“cameraman.tiff”, 0);
      if (im.empty()) {

      cout << "Can not load image !" << endl;
      return -1;
      }

      imshow("image", im);
      waitKey(0);

      return 0;
      }

      this is the complete face of the code

      1. Your code seems to be OK. But this is not enough. You need to add the references and includes to your project properly.

    2. Hi Diako, your English is quite fine. (better than mine perhaps 😉 )
      And yes, the incompatibility will definitely affect it.

Leave a Reply

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