ld: library not found for -lOpenGL::OpenGL

Manuel Alférez Ruiz
1 min readNov 19, 2020

--

Problem happens when running OpenGL on macOS, with a Makefile configuration for Debian GNU/Linux.

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})

grateful to Abdallah.

--

--