Unable to link OpenGL

Hi All,

I’m having trouble understanding why isn’t compiling opencv including OpenGL and Qt with it. (I have no reason to think this btw, this book is not making separate sections to install, instead it just uses libraries without any installs, it just compiles the openCV library and that’s it).

I’m on Intel macOS Big Sur, I installed opencv 4.5.4 using brew.
I will include my CMakeLists, followed by getBuildInformation(), then lastly an error message.

Here is my CMake:

# cmake version
    cmake_minimum_required (VERSION 3.0)

#project name
    project (myProject)

# Opencv Package required
    find_package(OpenCV REQUIRED)
    MESSAGE("OpenCV version : ${OpenCV_VERSION}")

    include_directories(${OpenCV_INCLUDE_DIR})
    link_directories(${OpenCV_LIB_DIR})

# generate our new executable
    add_executable(${PROJECT_NAME} main.cpp)
    target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

Here is the getBuildInformation() result:

General configuration for OpenCV 4.5.4 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /tmp/opencv-20220103-53048-1yv4jw7/opencv-4.5.4/opencv_contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2021-10-09T15:48:26Z
    Host:                        Darwin 20.6.0 x86_64
    CMake:                       3.22.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      requested:                 DETECT
      disabled:                  AVX AVX2
    Dispatched code generation:  FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      FP16 (0 files):            + FP16 AVX
      AVX (4 files):             + AVX
      AVX2 (30 files):           + FP16 FMA3 AVX AVX2
      AVX512_SKX (5 files):      + FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /clang++  (ver 13.0.0.13000029)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /clang
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-dead_strip  
    Linker flags (Debug):        -Wl,-dead_strip  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    hdf python2 world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv java julia matlab ovis ts
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI:                           COCOA
    Cocoa:                       YES
    VTK support:                 YES (ver 9.1.0)

  Media I/O: 
    ZLib:                        /Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/lib/libz.tbd (ver 1.2.11)
    JPEG:                        /usr/local/lib/libjpeg.dylib (ver 90)
    WEBP:                        /usr/local/lib/libwebp.dylib (ver encoder: 0x020f)
    PNG:                         /usr/local/lib/libpng.dylib (ver 1.6.37)
    TIFF:                        /usr/local/lib/libtiff.dylib (ver 42 / 4.3.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     OpenEXR::OpenEXR (ver 3.1.3)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    AVFoundation:                YES

  Parallel framework:            TBB (ver 2021.5 interface 12050)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   /tmp/opencv-20220103-53048-1yv4jw7/opencv-4.5.4/build/3rdparty/ippicv/ippicv_mac/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                /tmp/opencv-20220103-53048-1yv4jw7/opencv-4.5.4/build/3rdparty/ippicv/ippicv_mac/iw
    Lapack:                      YES (/usr/local/opt/openblas/lib/libopenblas.dylib)
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  NO
    Protobuf:                    /usr/local/lib/libprotobuf.dylib (3.19.1)

  OpenCL:                        YES (no extra features)
    Include path:                NO
    Link libraries:              -framework OpenCL

  Python 3:
    Interpreter:                 /usr/local/opt/python@3.9/bin/python3 (ver 3.9.9)
    Libraries:                   /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib (ver 3.9.9)
    numpy:                       /usr/local/lib/python3.9/site-packages/numpy/core/include (ver 1.22.0)
    install path:                lib/python3.9/site-packages/cv2/python-3.9

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local/Cellar/opencv/4.5.4_2
-----------------------------------------------------------------

Next, here is an error message from me trying to use Qt:

libc++abi: terminating with uncaught exception of type cv::Exception: OpenCV(4.5.4) /tmp/opencv-20220103-53048-1yv4jw7/opencv-4.5.4/modules/highgui/src/window.cpp:1227: error: (-213:The function/feature is not implemented) The library is compiled without QT support in function 'createButton'

I can’t have an error message for OpenGL but it’s also not working. I can’t use (compile) any OpenGL variables or functions.

Any help would seriously be appreciated. I think what I’m lacking is in my CMake file but too rookie to figure out what it is.

Hi,
please update your code with opencv master

I’m unable to update my code because I used homebrew to install. So I’m using their precompiled binaries.
I managed to #include GLUT into my .cpp file.
but now upon compiling my code I get many warnings saying OpenGL API is deprecated and multiple errors caused by OpenGL functions that lead to “Undefined symbols for architecture x86_64”.

Can you use git clone and cmake instead of homebrew?

I did use git clone just finally. I didn’t initially because there was a dependency conflict when I was compiling opencv. I did now and thankfully it worked. Now my issue is cmake not configuring Qt or OpenGL.

Thank you for all your help :slight_smile:

1 Like