ld: library not found for -lOpenGL::OpenGL

Replicating the error

CMakeList.txt

cmake_minimum_required(VERSION 2.8)
project(MY_PROJECT)find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)set(SRCS
src/main.cpp
)add_executable(MY_PROJECT
${SRCS})target_link_libraries(MY_PROJECT
OpenGL::OpenGL
OpenGL::GLU
${GLUT_LIBRARIES})

Compiling

[ 16%] Linking CXX executable MY_PROJECT
ld: library not found for -lOpenGL::OpenGL
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [MY_PROJECT] Error 1
make[1]: *** [CMakeFiles/MY_PROJECT.dir/all] Error 2
make: *** [all] Error 2

Solution

Changing the target link from OpenGL::OpenGL to OpenGL::GL, that is to say:

target_link_libraries(MY_PROJECT
OpenGL::GL
OpenGL::GLU
${GLUT_LIBRARIES})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store