Press ESC to close

Building OpenCV from Source for Older CPUs

In general, CPU architecture is not an issue when working with software as long as you have the right family of CPU in mind. For example, we know things run differently on AMD vs Intel vs PowerPC or they at least need to be code differently to take advantage of each architecture. Recently, I developed an application using OpenCV that was initially run on my Intel powered Apple MacBook Pro (mid-2009) and was deploying it to a now antiquated Google search appliance. The targeted machine was running Ubuntu 10.04 LTS so not the latest and greatest, but definitely something somewhat recent. After deployment I compiled everything down using G++ as opposed to XCode on my Mac. Surprisingly, I didn’t have any compilation errors, which made me extremely happy because the odds of something like going smoothly is not likely especially across different platforms. Well, I soon had problems. A larger/broader application makes use of this code via a worker and that code would consistently stall or hang when it came to the portion calling the OpenCV code. I recompiled OpenCV, did a lot of debug lines and still had nothing. Finally, I ran the C++ script by itself passing in some dummy values. The result: “Illegal instruction” from the command line. Such a descriptive error right? It turns out this is related to our CPU architecture and those fun SSE/SSE2 issues many of us first ran into at the onset of the Intel Pentium CPUs.

OpenCV or at least the latest versions assume that the CPU has SSE3 and that is unfortunate for older machines who don’t have SSE3. To get around this problem OpenCV needs to be built/compiled with the SSE3 flag disabled. Your cmake command probably looks something likes this:

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

To correct the situation just add the following option -D ENABLE_SSE3=OFF to the cmake command like so:

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 ENABLE_SSE3=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

Hopefully this will help you out and save you from hours of headaches.