Try to compile OpenGL 4 Helloworld in CLion + CMake + MinGW on Windows. & ldquo; undefined reference to `_imp____glewCreateShader '& rdquo; Errors

advertisements

This question already has an answer here:

  • What is an undefined reference/unresolved external symbol error and how do I fix it? 27 answers

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'


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