0

I'm trying to compile a simple Qt program with make after using CMake and I keep getting this error:

/usr/bin/ld: warning: libGL.so.1, needed by /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1, not found (try using -rpath or -rpath-link)
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glGetTexParameterfv'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glHint'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glClearColor'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glFlush'
...
collect2: error: ld returned 1 exit status

I have re-installed libgl1-mesa-dev via sudo apt install --reinstall libgl1-mesa-dev, made sure I have libGL.so.1 installed in my /usr/lib/x86_64-linux-gnu/mesa directory and I have run sudo ldconfig to no avail.

I'm not sure what is causing this and I haven't seen this problem anywhere else. It seems to be a dependency I'm ignoring, however I installed Qt using sudo apt install qt5-default so I would think the dependencies would be handled.

Here's my CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(SimpleQt)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOMOC ON)

find_package(Qt5Widgets CONFIG REQUIRED)

include_directories(include)

add_executable(SimpleQt src/main.cpp)

target_link_libraries(growth Qt5::Widgets)
robmor
  • 71
  • 6
  • Very similar issue, see [this answer](https://stackoverflow.com/a/9469349/3871028) – Ripi2 Jul 24 '18 at 16:28
  • Thanks for this. I managed to get it working, but I still don't feel I should have to link with OpenGL myself. – robmor Jul 24 '18 at 16:49

1 Answers1

0

I figured out a way to make it work thanks to Ripi2 in the comments. Apparently I had to link OpenGL with my project. Here's my updated CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(SimpleQt)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOMOC ON)

find_package(OpenGL Required) # Added this line
find_package(Qt5Widgets CONFIG REQUIRED)

include_directories(include ${OPENGL_INCLUDE_DIRS}) # Updated this line

add_executable(SimpleQt src/main.cpp)

target_link_libraries(growth Qt5::Widgets ${OPENGL_LIBRARIES}) # Updated this line

I'm leaving this unanswered though because this is definitely not how it should be. All the examples on Qt's site do not show OpenGL as a link requirement, so I feel there must be a better way.

robmor
  • 71
  • 6