Ok, so it turns out that I don't need to use the developer drivers to compile OpenCV after all!
I had somehow messed up my software sources such that I wasn't updating from ppa:ubuntu-x-swat/x-updates
any more. When I fixed that I was able to update my NVIDIA drivers to 304.43
from 295.49
. I think that might have been the critical factor for getting OpenCV to compile, although I did also have to modify one makefile to make it work.
If anyone's interested in doing the same, I basically followed the instructions here. To paraphrase:
sudo apt-get install
the following module dependencies if you don't already have them:
libopencv-dev build-essential checkinstall cmake pkg-config libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libv4l-dev
Download the latest OpenCV from here, then:
tar -xvf OpenCV-<version#>.tar.bz2
cd OpenCV-<version#>/
mkdir build
cd build
Run cmake
to configure a build file. You will need to pass cmake
a set of options to specify how you would like OpenCV to be built. The exact options will depend on your system - you can get some idea of what options are available by looking at ../CMakeLists.txt
. The exact command I used was:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON BUILD_TESTS=ON ENABLE_SSE3=ON ENABLE_SSE4.1=ON ENABLE_SSE4.2=ON WITH_CUDA=ON ..
I had particular trouble getting it to compile with CUDA runtime support (WITH_CUDA=ON
), hence the original question about the drivers.
cmake
will create a file called CMakeCache.txt
. I found that I had to modify this file as described here in order to avoid an error linking libcuda.so
.
Find the line that starts:
CUDA_CUDA_LIBRARY:FILEPATH=
And append the path to libcuda.so
, in my case:
CUDA_CUDA_LIBRARY:FILEPATH=/usr/lib/nvidia-current/libcuda.so
Now you should be able to run make
to compile (takes a while...), then sudo make install
to install
I hope somebody finds this useful.
Welcome to Super User! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. In other words, paraphrase those two links and just cite your source. It helps prevent link rot if those sites go down or the URL changes
– Canadian Luke – 2012-09-07T22:00:31.420Well, ok I suppose. My hesitation to do so is because it's information that's only very indirectly related to the topic of my original question. – ali_m – 2012-09-10T23:09:01.690
But if the site goes down, the average user may not know how you did it, and it eliminates the need for a question/answer site – Canadian Luke – 2012-09-10T23:24:29.813
Ok, I have edited my answer to paraphrase the content of the linked pages, and I have changed the topic of my original question to better match the content of the answer. – ali_m – 2012-09-10T23:45:46.870
Looks great! +1 – Canadian Luke – 2012-09-10T23:57:31.860