I installed OpenCV in a Vagrant box for a new project. It was a pain in the arse. The basic box I used was Official Ubuntu 13.10 daily Cloud Image amd64. After many trials and errors, these are things to note when installing OpenCV in a Vagrant box:
Build without GPU and OpenCL
When building, don’t build with GPU options:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_QT=ON -D BUILD_opencv_gpu=OFF -D BUILD_opencv_ocl=OFF ..
Building it with GPU on my local machine works, but in a VirtualBox env, there isn’t a GPU, and somehow it causes the compiler to come out with a odd error:
c++: internal compiler error: Killed (program cc1plus).
Download More RAM!
I was joking about downloading more RAM. But I spent about 4 hours figuring out why my compilation would segfault. It turns out that the virtual machine has very little memory and the compiler would run out of memory for no good reason.
So this was added to my Vagrantfile:
config.vm.provider "virtualbox" do |v| v.memory = 1024 end
The Right VirtualBox
In VirtualBox 4.2.x, I also encountered a problem where I couldn’t list the directories of
/vagrant. I discovered this problem when I was using
glob to search for files in the shared directory. It would consume so much memory and then the process would be killed. Doing
ls -a would also take a long time while in the box.
Turns out, it’s a known bug. My solution was simple: upgrade virtualbox to 4.3. Works beautifully now
Problems solved. It just takes 20 mins to compile OpenCV instead of 2 hours.
Not Everyone has Quad Cores
I found a bug within my provisioning script. When installing OpenCV, on some of my team’s computers, the make would fail. The reason? I had
make -j4 in the provisioning script. Updating it to
make fixed the problem for everyone