1

Googling aroung told me it was "wrong VS libraries" but when tried to use glew-1.5.4-mingw32 and libgluew32.a instead of glew32.lib (and same done to glut) nothing changed.

main.cpp got from project on VS2012, attaching same libs, so it may not be wrong.

Some files I use to make:

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4)
project(HelloGL)

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

add_executable(HelloGL main.cpp)

set(LIBS_DIR D:/libs)

set(GLEW_ROOT_DIR ${LIBS_DIR}/glew-1.5.4-mingw32 )
set(GLUT_ROOT_DIR ${LIBS_DIR}/glut-3.7.6-src/glut-3.7.6 )

set(GLEW_INCLUDE_DIRS ${GLEW_ROOT_DIR}/include)
set(GLUT_INCLUDE_DIRS ${GLUT_ROOT_DIR}/include)

set(GLEW_LIBRARY ${GLEW_ROOT_DIR}/lib/libglew32.a)
set(GLUT_LIBRARY ${GLUT_ROOT_DIR}/lib/glut/libglut32.a)


include_directories( ${GLEW_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )

target_link_libraries(HelloGL ${GLEW_LIBRARY} ${GLUT_LIBRARY} )

Part of LOG:

 "D:\Tools\CLion 140.569.17\bin\cmake\bin\cmake.exe" --build C:\Users\Alexey\.clion10\system\cmake\generated\dc6fcb22\dc6fcb22\Debug --target HelloGL -- -j 8
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/Alexey/.clion10/system/cmake/generated/dc6fcb22/dc6fcb22/Debug
    Linking CXX executable HelloGL.exe
    CMakeFiles\HelloGL.dir/objects.a(main.cpp.obj): In function `Z11LoadShadersPKcS0_':
    D:/Projects/CPP/HelloGL/main.cpp:19: undefined reference to `_imp____glewCreateShader'
    D:/Projects/CPP/HelloGL/main.cpp:20: undefined reference to `_imp____glewCreateShader'
    D:/Projects/CPP/HelloGL/main.cpp:56: undefined reference to `_imp____glewShaderSource'
    D:/Projects/CPP/HelloGL/main.cpp:57: undefined reference to `_imp____glewCompileShader'
    D:/Projects/CPP/HelloGL/main.cpp:60: undefined reference to `_imp____glewGetShaderiv'
    D:/Projects/CPP/HelloGL/main.cpp:61: undefined reference to `_imp____glewGetShaderiv'
    D:/Projects/CPP/HelloGL/main.cpp:64: undefined reference to `_imp____glewGetShaderInfoLog'
Aleksey Moroz
  • 31
  • 1
  • 4

3 Answers3

4

Try adding this line to your CMakeLists.txt:

add_definitions(-DGLEW_STATIC)

It seems that you are trying to link GLEW statically but you didn't define GLEW_STATIC

Nazar554
  • 4,105
  • 3
  • 27
  • 38
0

Did you compile GLEW yourself?

Generally the library called glew32 is dynamic linking and glew32s is static. MinGW really does not like the dynamic (DLL) version of GLEW and you should probably avoid it. The pre-built Windows dynamic GLEW libraries that are distributed on the GLEW site will not work with MinGW because of differences between Visual C++ and gcc's function naming convention for import libraries (it is a difference of one underscore, but enough to make life really difficult).

If you #define GLEW_STATIC before including <glew.h> and link to glew32s that will eliminate any potential issues with the dynamic linking library. In practice, this works best if you add the definition to your Makefile as Nazar554 has demonstrated.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
-2

This gist is how I compile OpenGL project in linux. Hope it helps

Maks
  • 82
  • 5