0

I was coding in KDevelop, ant I set up my CMakeLists.txt to include and link against libGL and freeglut.

However, it gave me the following error: make[2]: *** No rule to make target '/usr/lib/libGL.so', needed by 'opengl'. Stop.

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project(opengl)
add_executable(opengl main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS}  ${GLUT_INCLUDE_DIRS} )

target_link_libraries(opengl ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
user3166785
  • 77
  • 1
  • 8
  • Just chiming in, that on occasion I get the same error, but I never was able to figure out what causes it. It usually resolves by deleting the build directory and doing a fresh `cmake ${SOURCE_TREE}`. – datenwolf Mar 07 '15 at 20:56
  • How do you do that? I'm new to cmake. – user3166785 Mar 07 '15 at 21:14
  • By the way, libGL.so is in order, but has *many* symlinks – user3166785 Mar 07 '15 at 21:31
  • The usual way to work is to create a build directory outside of the source tree, `cd` to it and generate the makefiles from the source tree using cmake. For example `mkdir /tmp/builddir ; cd /tmp/builddir ; cmake /…/projectdir` – datenwolf Mar 07 '15 at 22:24

1 Answers1

0

First, what I am about to suggest might depend on CMake version, but I don't think (I'm using cmake version 3.1.0).

Looking at the installed FindOpenGL.cmake file, it looks like the variable you want in target_link_libraries is ${OPENGL_glu_LIBRARY}. Case does matter.

The best way to test an issue like this one is to use message("var: ${var}"), then you would be able to clearly see what your variable is set to during configuration.

Hope this helps!

FYI, I found the find module in the ${cmake_install_dir}/Modules/Find* where cmake_install_dir=/usr/share/cmake on my linux machine.

EDIT** Sorry, was tired this morning and missed that you wanted GLUT, not GLU. There is a FindGLUT.cmake Module. You should call find_package(GLUT REQUIRED) and use ${GLUT_LIBRARIES} and ${GLUT_INCLUDE_DIR}. Sorry about the confusion!

StAlphonzo
  • 736
  • 5
  • 14