[CMake] CMAKE 2.8.9, OS X 10.8 and OpenGL

Jason T. Slack-Moehrle slackmoehrle at gmail.com
Wed Aug 15 17:52:09 EDT 2012


Hi Benjamin,

I modified my CMakeLists.txt file a bit:

PROJECT(Test)

SET(TEST_VERSION 0.1+devel)
SET(PROJECT_NAME test)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
SET(CMAKE_INCLUDE_CURRENT_DIR TRUE)

SET(CMAKE_C_COMPILER "clang")
SET(CMAKE_CXX_COMPILER "clang++")

SET(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")

IF(APPLE)
   find_package(OpenGL REQUIRED)
   include_directories(${OPENGL_INCLUDE_DIR})

   INCLUDE_DIRECTORIES ( /System/Library/Frameworks )
   FIND_LIBRARY(COCOA_LIBRARY Cocoa)
   FIND_LIBRARY(GLUT_LIBRARY GLUT )
   FIND_LIBRARY(OpenGL_LIBRARY OpenGL )
   MARK_AS_ADVANCED (COCOA_LIBRARY
                     GLUT_LIBRARY
                     OpenGL_LIBRARY)
   SET(EXTRA_LIBS ${COCOA_LIBRARY} ${GLUT_LIBRARY} ${OpenGL_LIBRARY})
ENDIF (APPLE)
#target_link_libraries(Test ${EXTRA_LIBS})

add_executable(Test main.cpp)

> for OpenGL, better use the shipped find module (see "cmake --help-module
> FindOpenGL"):
>
> find_package(OpenGL REQUIRED)
> include_directories(${OPENGL_INCLUDE_DIR})
> [...]
> target_link_libraries(Test ${OPENGL_LIBRARIES})

I get errors:

$ make
Scanning dependencies of target Test
[100%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
Linking CXX executable Test
Undefined symbols for architecture x86_64:
  "_glClear", referenced from:
      display() in main.cpp.o
  "_glViewport", referenced from:
      reshape(int, int) in main.cpp.o
  "_glutCreateWindow", referenced from:
      _main in main.cpp.o
  "_glutDisplayFunc", referenced from:
      _main in main.cpp.o
  "_glutIdleFunc", referenced from:
      _main in main.cpp.o
  "_glutInit", referenced from:
      _main in main.cpp.o
  "_glutInitDisplayMode", referenced from:
      _main in main.cpp.o
  "_glutInitWindowSize", referenced from:
      _main in main.cpp.o
  "_glutMainLoop", referenced from:
      _main in main.cpp.o
  "_glutPostRedisplay", referenced from:
      idle() in main.cpp.o
  "_glutReshapeFunc", referenced from:
      _main in main.cpp.o
  "_glutSwapBuffers", referenced from:
      display() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Test] Error 1
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
make: *** [all] Error 2

> Furthermore, I suggest using an out-of-source build. I cannot answer your
> other question. On my Linux system I do not get these error messages.

Can you tell me what you mean by 'out-of-source build"?

-Jason


More information about the CMake mailing list