Undefined Symbols when linking project with GLFW3 using CMake on OSX -


I am following the creation of a project using GLFW3 with CMake on OSX 10.9.1, and I Trouble has run When I get the actual project I get the following errors:

  $ target scanning dependency graphics [100%] Building CSF Object CMakeFiles / Graphics.dir / graphics.cpp.o Linking CXX performance graphics architecture refers to the undefined symbols: "_glBegin", for x86_64: in graphics.cpp.o _main "_glClear", refers to: _main in graphics.cpp.o "_glColor3f", refers to: _main in graphics.cpp . O "_glEnd", refer to: refer to "_glLoadIdentity" _main, in graphics.cpp.o: in graphics.cpp.o "_glMatrixMode" _main, refer to: _main referenced, "_glOrtho" in graphics.cpp.o: _main "_glRotatef" in graphics.cpp.o, refer to: _main referenced, "_glVertex3f" in graphics.cpp.o: _main referenced, "_glViewport" in graphics.cpp.o: graphics.cpp.o _main in ld : Symbol for Architecture (s) not found x86_64 Clag: Error: Lynch command exits out of command c ODE 1 (to invite -V to invite) [2]: *** [Graphics] make error 1 [ 1]: *** [CMakeFiles / Graphics.dir / all] Make Error 2: *** [All] Error 2  

My CMakeLists.txt looks:

  cmake_minimum_required (version 2.8) Project (Graphics) # Version Number Set (Graphics_VERSION_MAJOR 1) Set (Graphics_VERSION_MINOR 0) # Configure a header file source code configure_file ( "$ {PROJECT_SOURCE_DIR} /GraphicsConfig.h.in" "$ {PROJECT_BINARY_DIR} CMake settings /GraphicsConfig.h # to a pass" ADD) # Add the binary tree search path for the file # so we GraphicsConfig.h Shamil_direrijh ( "$ {PROJECT_BINARY_DIR}") Get _ package (PkgConfig rEQUIRED) pkg_search_module (GLFW required glfw3) Shamil_ directory ($ {GLFW_INCLUDE_DIRS}) # Adding Execution Add_executable (graphics graphics.cpp) target_link_libraries (Graphics $ {GLFW_STATIC_LIBRARIES}) # Installation However, the use of the project is only  
 to install targets (Target Graphics Destination Bin) (files "$ {PROJECT_BINARY_DIR} /GraphicsConfig.h" included in the destination)  

cc `pkg-config -cflags glfw3` - no graphics graphics. Cpp \` pkg-config -static -libs glufow 3`

I can not give you an explanation for why there is no link to OpenGL Libs and the other is not, but the following solution works for me Have done a similar problem on OSX (Mountain Lion).

{GLFW_STATIC_LIBRARIES}) if (Apple) target_link_libraries (graphics "-framework Open") endif ()

I'd add performance add_executable should be responsible Jielfdbluemkekek config to add Opanjiel lib, So I took a look and found that 'framworkwork' lai not.

This will only help you on OSX - you need to provide other platform specific ways of linking it to cross the platform.

You have already accepted it, but the same guide also provides in such a way and it can be made in the same way. Perhaps the easiest way to guarantee cross-platform compatibility.


Comments