How to Build OpenCV 3.1 with MSVC2010 for x86

OpenCV 3.1 was released yesterday and with a first look I noticed that prebuilt libraries for x86 VC10 (MSVC2010) are nowhere to be found in the installation folder. In fact there is no x86 folder to begin with. Some of my recent apps all are built using MSVC2010 so I had to build OpenCV myself. Here is what I did and what I suggest you should do.

Previously I wrote a guide about building OpenCV 2.4.11 with VC14. In fact building OpenCV 3.1 with VC10 is quite similar if not the same. Please read this guide first and then check out the differences below:

The only obvious and very simple differences are :

  • You need to install Microsoft Visual C++ 2010 (Express)
  • You have to select MSVC 2010 (VC10) compiler while running CMake configure.


I built OpenCV 3.1 successfully myself but if you are still unable to build using this guide then just put a comment bellow to start a conversation about it.

Good luck!

26 Replies to “How to Build OpenCV 3.1 with MSVC2010 for x86”

  1. Hi,I am trying to build OpenCV3.4.1 with vs2010 in Windows XP sp3 x86.
    In the cmake configuration,I checked BUILD_STATIC_CRT and unchecked the BUILD_SHARD_library option ,So can I get static library.
    ,And I remove IPP ,itt,ipp_iw,and videoio modules ,because they use the windows API without XP support,
    Finally,I build it successfully,
    I created a new vs project to test my opencv static lib, then add include path ,add lib path,add opencv_world340.lib to lib list,I build the test application successfuly,But it crashed when it run,
    I have spent a lot of time and effort,But it still doesn’t work!I don’t know how to proceed next.
    Is there anyone can help me?
    I will provide more information.
    Please contact me with email : #####,Thanks a lot

    1. No error messages at all?!

      You need to make sure the DLL files for OpenCV are visible to your application, for instance by adding them to the PATH.
      Since you are using static libraries, you won’t need exactly OpenCV DLL files, but still FFmpeg (and maybe some other DLLs, I’m not sure) which are not built statically, must be visible to the application.
      Let me know if this helps.

      One more thing, please do not share your personal email address in the comments, I already edited it out but just in case for the future 🙂

  2. Hi Amin,

    Is it possible to use latest opencv pre-built libraries for windows with visual studio 2008 for x86? or can I compile it with VS 2008?

    1. Well the question is actually about the C++ compiler that is shipped with VS 2008. So, two points:
      1. I would avoid using C++ libs meant for other compilers (or compiler versions)
      2. I would be surprised to see latest versions built with compilers that do not support C++11, and yes, VS 2008 does not ship with a compiler that supports C++11.

      I hope this helps.

      1. Hi Amin,

        I’ve succesfully build OpenCV 3.3 for x64. However we’d like to build for 32bit as well. If in cmake-gui I simply selected Visual Studio 14 2015 (as opposed to Visual Studio 14 2015 Win64) then I get errors during the configuration process that CMake cannot find 32bit versions of the CUDA libs that all of the opencv modules depend on.

        I’ve read that CUDA toolkit no longer ships 32 bit versions of their libs as they are now deprecated. I’ve also read that I could still build for 32 bit if I crossed compiled an x64 solution to target win32. Unfortunately I have no idea how to configure cmake-gui to generate a 64 bit project that targets win32, any thoughts?
        Thanks!

        1. Hmmm, sounds strange. Can you please clarify the following:

          * Do you want to build OpenCV with all default configurations?
          * Do you change anything? If so, the what exactly?

          As for the last part, I am still not sure if I got it correctly but generally speaking something that is meant for 64 bit can’t be used with 32 bit (it usually works the other way around)

          However, I am able to build OpenCV 3.3 using MSVC14 (2015) 32 bit without any issues, using all default settings.

          1. Hi Amin,

            Similar problem here with VS 17 can’t find the gdi32.lib when using CMAKE,
            Think its a VS problem as general WIN32 gui build fail due to not finding the gdi32.lib.

            The paths have to be manually added to the lib library paths.
            Any idea on how to specify additional search paths for libs in CMAKE file?

          2. Are you sure you are using “Developer Command Prompt for VS 2017” and NOT “Command Prompt”?!
            Anyway, this shouldn’t happen if you have a correct installation of VS 2017 and Windows SDKs.
            I would recommend a complete uninstall and reinstall of VS 2017.
            However, to answer your specific question, you can add any paths you like to the “PATH” environment variable and CMake will take it automatically.
            You can also use the “Add Entry” button in CMake GUI when configuring.

          3. Thanks will try Add entry.
            It does look as though its a general problem with missing gdi32.lib in the SDK library folder for latest VS2017 installation or as on some sites are saying its removed during the update to the Windows 10 Creators addition!

          4. It’s still quite strange, since I am using the latest update for Windows and VS 2017 without any issues. In any case, if it’s mainly for Qt and OpenCV, you can safely use VS 2015 until there’s an update for VS 2017.

  3. Hello Amin,

    Thanks for the post! could you precise how to select the compiler? actually, cmake (version 3.7) proposes to “specify native compilers” at the comfiguration step. Then it asks for a path, for fortrans C and C++, which path should we give it ,if it is the right way to do? thanks in advance

    1. Usually you don’t need to specify the compiler by yourself. Are you sure you have a compiler installed and in the PATH? CMake should be able to find it automatically.

  4. I am having big trouble with it. I have successfully built it and i have the OpenCV.sln file. I am able to open the solution in ***VS15*** but I cant build it there. I get LNK1112 error. what should I do?

    I don’t even have that opencv\build\x86 folder to use in CMake, I only have x64 one. I downloaded opencv from http://opencv.org/downloads.html > OpenCV for Windows (3.1).
    What should I do?

    1. forget thesecond part of my comment. how do I solve the first part?

      Severity Code Description Project File Line Suppression State
      Error LNK1112 module machine type ‘x64’ conflicts with target machine type ‘X86’ opencv_python2 D:\tools\opencv-build\modules\python2\python27.lib(python27.dll) 1

      1. Can you tell me which version of Visual Studio you are using for building? Is it x86 or x64?

        It seems you are creating project for one version and then try to build it with another version of VS.

  5. I’m trying to install OpenCV 3.1.0 with MSVC2012 compiler using CMake. I get an error saying that the file hash is different from the expected hash.
    Download: Local copy of opencv_ffmpeg.dll has invalid MD5 hash: d41d8cd98f00b204e9800998ecf8427e (expected: 89c783eee1c47bfc733f08334ec2e31c)

    how to fix this?

    1. Check your network connection and reconfigure again. invalid MD5 hash value means you don’t have the correct files or they are corrupted. (can happen due to a faulty connection.)

  6. hi
    i want build OpenCV 3.1 with MSVC2012 FOR x64
    but in cmake when i click on configure, i get this error “error in configuration process project files may be invalid”

    how can fixed this?

    1. Unfortunately not. And I highly recommend against using someone else’s build. I would gladly help you build one exactly like mine for yourself 🙂

  7. Hi, in the x64 lib folder there is only one .lib file for release and one for debug.

    After building for x86, I have multiple .libs for both release and debug (similar to previous 2.4.12 version).

    Is this normal ?

    Thanks!

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.