0

When I compile my old program with CMake I keep getting this message:

-- WARNING: you are using the obsolete 'GLU' package, please use 'OpenGL' instead

OK, so I tried to remove this form CMakeFiles

find_package( OpenGL REQUIRED )
#find_package( GLU    REQUIRED )
find_package( SDL2   REQUIRED )

add_executable       ( test_app test_app.cpp $<TARGET_OBJECTS:SDL2OGL> $<TARGET_OBJECTS:DynamicOpt>  )
#target_link_libraries( test_app ${OpenGL_LIBRARY} ${GLU_LIBRARY} ${SDL2_LIBRARY} )
target_link_libraries( test_app ${OpenGL_LIBRARY} ${SDL2_LIBRARY} )

But then the legacy OpenGL functions are undefined?

undefined reference to `glTranslatef'
undefined reference to `glPopMatrix'
undefined reference to `glPushMatrix'
undefined reference to `glCallList'
undefined reference to `glColor3f'
undefined reference to `glDisable'
undefined reference to `glShadeModel'
...

So I don't know, what should I do to link it against OpenGL properly. Do I need GLU for legacy OpenGL or not?

EDIT:

aha so the whole problem was that I had OPENGL_LIBRARY instead of OPENGL_LIBRARIES, as pointed by Tsyvarev, Thanks!

In other words, It turned out, I was using GLU_LIBRARY just to replace missing OPENGL_LIBRARIES

Prokop Hapala
  • 2,424
  • 2
  • 30
  • 59
  • 2
    Correct spelling of a variable, containing OpenGL libraries to link, is `OPENGL_LIBRARIES` (not `OPENGL_LIBRARY` as you are trying to use). This can be found in documentation for [find_package(OpenGL)](https://cmake.org/cmake/help/latest/module/FindOpenGL.html). If you are updating your project for current CMake, then for link with OpenGL (and other packages) it is better to use IMPORTED *targets*, not *variables*. For more details see [duplicate question](https://stackoverflow.com/questions/9460242/how-to-compile-glut-opengl-project-with-cmake-and-kdevelop-in-linux) and its answers. – Tsyvarev Sep 19 '22 at 10:41
  • @Rabbid76: Given question has a clear attempt to link a library: a call to `target_link_libraries`. That attempt fails just because of CMake specifics. Please, do not close such questions as a duplicate for generic "undefined reference" question, which describes only C/C++ specific reasons. – Tsyvarev Sep 19 '22 at 10:44
  • aha so the whole problem was this `OPENGL_LIBRARY` vs `OPENGL_LIBRARIES` ! THANKS! – Prokop Hapala Sep 19 '22 at 12:27
  • On Stack Overflow we expect a question post to contain only **problems**. Please, revert your edit which adds **solution** to question post. – Tsyvarev Sep 19 '22 at 13:24

0 Answers0