This post describes how to build an static version of OpenCV for Linux operating systems. I am going to use OpenCV version 3.1.0 and Ubuntu 16.04 64-bit but the process should be more or less the same under CentOS or other flavors of Linux. So let’s start.
Following are the requirements for building OpenCV:
- OpenCV 3.1.0 for Linux/Mac (can be found here)
- CMake (just use Ubuntu Software to get it. I am going to use the CMake GUI to comfortably set all the options but if you feel more like a genius by typing some commands in the terminal then you can go ahead and type “sudo apt-get install cmake” and some similar commands to get it.)
Extract OpenCV archive and run CMake. Make sure you set the source and bin folders as seen below. (Of course you should use the folder paths from your own computer and PLEASE don’t use my name, please.) Just make sure build folder is under the source folder.
Now hit Configure button. You will be asked to approve creating the binaries folder as seen below. Just press Yes to continue.
Next you have to make sure Unix Makefiles are selected in the CMakeSetup dialog as seen here. Press Finish to proceed.
And Yes, now you have to wait for the following to appear. Be patient.
Go through the options in red and make sure to uncheck BUILD_SHARED_LIBS option.
Also change CMAKE_INSTALL_PREFIX to where you want to install your static libraries. I prefer my home folder so I set CMAKE_INSTALL_PREFIX option to “/home/amin/opencv”
After setting the above options make sure you press Configure once again. After it’s done, press Generate to create make files.
You can safely close CMake and forget it ever existed.
Now it’s time to start compiling OpenCV, so open up a terminal window and enter the following commands:
cd Downloads/opencv-3.1.0/build sudo make
No need to repeat that you have to enter the same folder you did for binary folder in CMake instead of “Downloads/opencv-3.1.0/build” right?
Wait for a while until building is finished. Then enter one last command to finish it off.
sudo make install
Voila, now you have a static build of OpenCV 3.1.0 under the same folder you entered for CMAKE_INSTALL_PREFIX. Mine was “/home/amin/opencv” so if I check that folder you’ll see that I have all required files there.