Trouble compiling OpenCV for Linux on an Optimus laptop using bumblebee

3

OK, I have a pretty specific Optimus/CUDA/drivers question:

  • I'm running Ubuntu 12.04 on an Acer Aspire 5750G. This laptop has a CUDA-capable GT540M GPU, but it also has Optimus, so in order to make use of it I need to use bumblebee

  • Following these instructions I installed more recent NVIDIA drivers from ppa:ubuntu-x-swat/x-updates, then installed bumblebee

  • I can now run stuff on the GPU just fine (optirun glxspheres works as expected)

  • However, I'm trying to compile something (OpenCV-2.4.2) with CUDA runtime support, and I hit a compiler error that seems to be to do with not having the NVIDIA CUDA developer drivers installed

What I want to know is whether it's possible to use bumblebee in combination with the NVIDIA developer drivers. Is it safe to use the installer downloaded from NVIDIA's developer page, or will that totally mess up bumblebee? Is there a better way to install the developer drivers? I looked for an up-to-date PPA but couldn't find one.

ali_m

Posted 2012-09-05T10:12:08.340

Reputation: 486

Answers

4

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.

ali_m

Posted 2012-09-05T10:12:08.340

Reputation: 486

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

Well, 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