0

I am trying to learn opengl for a class but am having trouble with getting setup. I am using Windows, with the IDE CLion, and cygwin64. So far I have been able to compile and run Gl.h and Glu.h but I am having trouble getting the static library for freeglut.

Right now programs error on the last line in the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)
project(OpenGLAugust)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(OpenGLAugust ${SOURCE_FILES})
target_link_libraries(OpenGLAugust libopengl32.a libglu32.a libfreeglut.a)

with error

cannot find -lfreeglut
collect2: error: ld returned 1 exit status

I looked into it and it appears that after downloading freeglut I need to create the library files (specifically the .a file libfreeglut32.a) from the source code. I have tried looking for an explanation on how it is done but haven't found an answer. Would anyone be able to help explain how to do this?

1 Answers1

1

Unlike OpenGL, which availability in a compiler toolchain is mandated by the Windows ABI, FreeGLUT is an optional 3rd party library that must be installed separately.

Most simple course of action would be to simply drop FreeGLUT sources into a subdirectory of your project and just add it to your CMakeLists.txt; FreeGLUT comes with a ready to use CMake configuration, so that will "just work".

On a side note, you should not use

target_link_libraries(OpenGLAugust libopengl32.a libglu32.a …)

but

find_package(OpenGL)
target_link_libraries(OpenGLAugust
    ${OPENGL_gl_LIBRARY}
    ${OPENGL_glu_LIBRARY}
    … )

I.e. in total you should extract FreeGLUT sources into a subdirectory of your project and change your CMakeLists to

cmake_minimum_required(VERSION 3.5)
project(OpenGLAugust)
find_package(OpenGL)
add_subdirectory(freeglut)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(OpenGLAugust ${SOURCE_FILES})
target_link_libraries(OpenGLAugust
        ${OPENGL_gl_LIBRARY}
        ${OPENGL_glu_LIBRARY}
        freeglut_static )
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Now I am getting an error of "could not find X11". I went and downloaded cygwin/x including the x-org server and xinit but still that does not work. – Chris Procak Aug 02 '16 at 17:35
  • 1
    @ChrisProcak: Well, the problem you're running into is, that Cygwin tries to provide maximum compatibility with Linux. And in Linux you do graphics through an X server. But in Windows there is no X server (unless you start the X server that comes with Cygwin, but the OpenGL support of that is meager at best). *Instead of Cygwin I strongly advise you to use MinGW to compile your project. The easiest way to install it is using the MSys2 installer https://msys2.github.io/ to get a MSys2 environment, and then install mingw inside it. That will give you native OpenGL support, which you want.* – datenwolf Aug 02 '16 at 17:52