12

I am trying to build OpenCV 2.4.1 with OpenGL support, and it keeps faling. I have OpenGL installed in my Ubuntu 11.04, libs are under /usr/lib/libGL.so as usual. I know my OpenGL installation is correct because I have C++ OpenGL projects that compile, link and run OK.

I run the cmake command as follows, because I want both CUDA and OpenGL support.

/data/OpenCV-2.4.1/build $ cmake -D WITH_OPENGL=ON -D CMAKE_BUILD_TYPE=RELEASE -D WITH_CUDA=ON -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ -D BUILD_EXAMPLES=ON -D WITH_TBB=ON ..

This is the output I get from this, telling me CUDA was properly detected, but OpenGL wasn't

-- General configuration for OpenCV 2.4.1 =====================================
-- 
--   Platform:
--     Host:                        Linux 2.6.35-32-generic x86_64
--     CMake:                       2.8.8
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++ (ver 4.4.4)
--     C++ flags (Release):         -Wall -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -O3 -DNDEBUG   -DNDEBUG
--     C++ flags (Debug):           -Wall -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     C Compiler:                  /usr/bin/gcc
--     C flags (Release):           -Wall -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -Wall -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     Linker flags (Release):      
--     Linker flags (Debug):        
-- 
--   OpenCV modules:
--     To be built:                 calib3d contrib core features2d flann gpu highgui imgproc legacy ml nonfree objdetect photo python stitching ts video videostab
--     Disabled:                    -
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera java
-- 
--   GUI: 
--     QT 4.x:                      NO
--     GTK+ 2.x:                    YES (ver 2.22.0)
--     GThread :                    YES (ver 2.26.1)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib64/libz.so (ver 1.2.3.4)
--     JPEG:                        /usr/lib64/libjpeg.so (ver 62)
--     PNG:                         /usr/lib64/libpng.so (ver 1.2.44)
--     TIFF:                        /usr/lib64/libtiff.so (ver 42 - 3.9.4)
--     JPEG 2000:                   /usr/lib64/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib64/libImath.so /usr/lib64/libIlmImf.so /usr/lib64/libIex.so /usr/lib64/libHalf.so /usr/lib64/libIlmThread.so (ver 1.6.1)
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  NO
--     FFMPEG:                      YES
--       codec:                     YES (ver 54.23.100)
--       format:                    YES (ver 54.6.100)
--       util:                      YES (ver 51.54.100)
--       swscale:                   YES (ver 2.1.100)
--       gentoo-style:              YES
--     GStreamer:                   
--       base:                      YES (ver 0.10.30)
--       app:                       YES (ver 0.10.30)
--       video:                     YES (ver 0.10.30)
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    Using libv4l (ver 0.8.8)
--     Xine:                        NO
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use TBB:                     YES (ver 3.0 interface 5000)
--     Use Cuda:                    YES (ver 4.2)
--     Use Eigen:                   YES (ver 2.0.15)
-- 
--   NVIDIA CUDA:                   (ver 4.2)
--     Use CUFFT:                   YES
--     Use CUBLAS:                  NO
--     NVIDIA GPU arch:             11 12 13 20 21 30
--     NVIDIA PTX archs:            11 12 13 20 21 30
--     NVIDIA GPU features:         11 12 13 20 20 30 20
-- 
--   Python:
--     Interpreter:                 /usr/bin/python (ver 2.6.6)
--     Libraries:                   /usr/lib64/libpython2.6.so (ver 2.6.6)
--     numpy:                       /usr/local/lib/python2.6/dist-packages/numpy/core/include (ver 2.0.0.dev-27befc8)
--     packages path:               lib/python2.6/dist-packages
-- 
--   Documentation:
--     Build Documentation:         NO
--     Sphinx:                      NO
--     PdfLaTeX compiler:           /usr/local/texlive/2011/bin/x86_64-linux/pdflatex
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     Examples:                    YES
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /data/OpenCV-2.4.1/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /data/OpenCV-2.4.1/build

Any guess what is missing?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Dan
  • 1,466
  • 1
  • 13
  • 27

6 Answers6

17

You probably forgot to install the GTK+ OpenGL Extensions and their headers

sudo apt-get install libgtkglext1 libgtkglext1-dev
Lincoln
  • 744
  • 1
  • 7
  • 20
  • This seems to be the answer but it was first suggested by @AndreyKamaev in his comment :) – Rui Marques Jun 17 '12 at 12:19
  • Well, as @RuiMarques said, this was already answered by Andrey in a comment, but I will take this answer as the correct one because I cannot accept a comment, and I want to close this question. – Dan Jun 17 '12 at 21:48
  • 4
    Not sure how this is the right answer. Installing this makes CMake find `GtkGlExt` (the line right above OpenGL), but `OpenGL support` is still NO. – Subhamoy S. Oct 25 '13 at 23:12
6

I have the same problem and I fund a solution by putting a extra command (WITH_QT=ON). I dont know why, but I found on the internet that is not possible enable OPENGL without enableing QT instead of GTK. I hope that this help us, and Iam sorry for my english (I dont know so much because I talk spanish).

Saludos compadres !! Desde Mexico :D

  • There is a way to enable OpenGL with GTK+ 2.0 and without QT. See https://stackoverflow.com/questions/33801083/build-opencv-3-0-with-opengl-and-gtk-on-lmde2-debian-8-2 – kaartic Aug 09 '18 at 15:20
  • 1
    On Ubuntu 20.02 installed `libqt5opengl5-dev` and using flag `WITH_QT=ON` I finally had OpenGL enable in the make. Thanks. – Torrien Jun 20 '20 at 01:17
  • This also worked for me inside an Ubuntu 18.04 Docker image with `ibgtkglext1` and `libgtkglext1-dev` already installed. Gracias @angel-xipootle! – indirectlylit Nov 17 '21 at 17:21
2

I couldn't get the WITH_OPENGL flag to show up in my openCV 2.4.3 CMake options (I am running on a Mac - Snow Leopard 10.6.8)... I finally got it working by just opening up CMakeLists.txt and editing line 128 to:

OCV_OPTION(WITH_OPENGL "Include OpenGL support" ON)

Then run your CMake configurator/generator and it should build.

Amir Rubin
  • 850
  • 7
  • 11
  • 2
    This didn't build on OSX 10.8 because of a reference to glXUseXFont in modules/highgui/src/window_QT.cpp. However, if I simply comment out this one line, the project will build (after editing the CMakeList.txt file as indicated by Amir Rubin). I'm in the middle of testing if removing this line causes any problems. So far so good. – Angus Forbes Feb 07 '13 at 19:57
  • 1
    @AngusForbes Ha - exact same thing happened to me; I forgot to mention it in my reply. I haven't encountered anyproblems from commenting out that line: http://code.opencv.org/issues/1603 – Amir Rubin Feb 07 '13 at 21:27
  • In the current version's root CMake, this is now line 143. I tried this there, and CMake still says `OpenGL support` is NO in Ubuntu 13.10 x64. – Subhamoy S. Oct 25 '13 at 23:14
0

If OpenGL is installed:

apt-get install libgl1-mesa-dev libglu1-mesa-dev libqt4-opengl-dev

And still CMake cannot find OpenGL, then it means there is no libGl.so in /usr/lib/x86_64-linux-gnu/. If there is libGl.so in /usr/lib/x86_64-linux-gnu/mesa/, then this is a case of a missing softlink. Just reinstalling the packages should re-establish that link.

apt-get install --reinstall libgl1-mesa-dev libglu1-mesa-dev libqt4-opengl-dev

Please note that I had to install libqt4-opengl-dev even though I did not care about Qt support in OpenCV or Qt support anywhere else. I am trying to figure out myself why a hefty 80MB or download and install was necessary to make the regular OpenGL work, but this method certainly works in Ubuntu 13.10.

Subhamoy S.
  • 6,566
  • 10
  • 37
  • 53
  • There is a way to enable OpenGL with GTK+ 2.0 and without QT. See https://stackoverflow.com/questions/33801083/build-opencv-3-0-with-opengl-and-gtk-on-lmde2-debian-8-2 – kaartic Aug 09 '18 at 15:20
0
cmake -D:WITH_OPENGL=ON

for Dan's comment. on openCV 2.4.6

Taryn
  • 242,637
  • 56
  • 362
  • 405
gitfredy
  • 399
  • 4
  • 3
-2

Run cmake with option:

cmake -DWITH_OPENGL=ON <your CMakeLists.txt directory>

or

cmake -DUSE_OPENGL=ON <your CMakeLists.txt directory>
Eric
  • 2,301
  • 3
  • 23
  • 30
  • Doesn't work. cmake expects expressions like "VAR:type=value". If I run it with -DWITH_OPENGL or -DUSE_OPENGL Parse error in command line argument: -D Should be: VAR:type=value CMake Error: No cmake script provided. CMake Error: Problem processing arguments – Dan Jun 14 '12 at 15:04
  • I believe the proper way should be -D WITH_OPENGL=ON but I am already doing this and no luck. – Dan Jun 14 '12 at 15:05
  • If you are running on linux you can install ccmake and add the option WITH_OPENGL easily. – Eric Jun 14 '12 at 15:06