libGL.so undefined reference error when building OpenCV 3.3.0

Dear All,

Early this month I got my TX2 and started playing with it. I installed Caffe, Opencv 3.3.0 by following the Github wiki and everything was perfectly fine. Until three days ago I installed ROS Kinetic and messed up with the sources.list file, so I decided to reflash the whole system, re-install everything, so that I can clone the entire TX2 image in case things go south in the future.

I have been using Jetpack 3.1 with L4T-28.1. When I followed the steps to build OpenCV 3.3.0, I encountered such kinda error saying:

[ 43%] Linking CXX executable ../../bin/opencv_annotation
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmCloseOnce'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmMap'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmUnmap'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmFreeDevice'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmGetDevices'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmGetDevice'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmOpenOnce'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmFreeDevices'
collect2: error: ld returned 1 exit status
apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:103: recipe for target 'bin/opencv_annotation' failed
make[2]: *** [bin/opencv_annotation] Error 1
CMakeFiles/Makefile2:12165: recipe for target 'apps/annotation/CMakeFiles/opencv_annotation.dir/all' failed
make[1]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Eventually I solved this using “-D WITH_OPENGL=OFF” to skip OpenGL, and rebuilt everything. But I would like to know if there is a solution to this? And what would possibly be the cause of this error? Since I’ve done all the installations exactly the same as before (Maybe the apt-get update && upgrade?). Many thanks!

You may check this: https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945.

It worked like a charm! Thank you so much!

It works! Thanks a lot!