Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Problems adding GLFW3 to an existing CMAKE project

Using GLFW
flapstah
2014-07-14
2014-07-16
  • flapstah
    flapstah
    2014-07-14

    Hi,

    I've been trying to solve how to add GLFW3 (from source) to an existing CMAKE project. I've been searching the forums and the internet at large but I haven't found an answer yet so I wondered if the community had any insight to offer? For reference, I'm compiling under a MINGW32/MSYS shell on a Windows 7 PC (but I also need Visual Studio and Linux support, hence using CMAKE).

    I've added GLFW3 from github in my project folder, and followed the instructions (http://www.glfw.org/docs/latest/build.html) for adding it as a dependency of my project, so my CMakeLists.txt has the following:

    add_subdirectory(path/to/glfw)
    include_directories(path/to/glfw/include)
    target_link_libraries(myapp glfw ${GLFW_LIBRARIES})

    (I've changed the paths to be correct for my project)

    Both GLFW and my project compile fine, but it fails to link (missing symbols include such things as glfwInit and glfwTerminate, amongst others). According to the documentation, GLFW_LIBRARIES should be set correctly, but when I added:

    message("GLFW [${GLFW_LIBRARIES}]")

    to my CMakeLists.txt in an effort to find out what was going on, the output is:

    GLFW [-lpthread;opengl32]

    I was expecting to also see something like glfw.lib or glfw.a as I wish to link statically with GLFW if possible.

    Has anyone else seen this behaviour, and if so, does anyone know how to fix it in a platform independent way? I'm reasonably confindent with CMAKE but I'm the first to admit I'm no expert.

    Many thanks in advance for any suggestions.

     
  • flapstah
    flapstah
    2014-07-16

    SOLVED: I was referencing GLFW calls in a library in my project, rather than in the main application, so the solution was to use:

    target_link_libraries(mylib glfw ${GLFW_LIBRARIES})

    (note 'mylib' instead of 'myapp' - didn't need to link glfw with myapp at all)

    Hope this saves someone else some time.