试图在Windows上的CLion + CMake + MinGW中编译OpenGL 4 Helloworld。 “未定义引用`_imp____glewCreateShader'”错误

时间:2015-01-18 15:55:25

标签: c++ opengl cmake mingw32 clion

谷歌用谷歌搜索告诉我这是错误的VS库"但是当试图使用 glew-1.5.4-mingw32 libgluew32.a 而不是 glew32.lib (并且完全相同)改变。

main.cpp 从VS2012上的项目获得,附加相同的库,所以它可能没有错。

我用来制作的一些文件:

的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} )

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'

3 个答案:

答案 0 :(得分:3)

尝试将此行添加到CMakeLists.txt

add_definitions(-DGLEW_STATIC)

您似乎尝试静态链接GLEW,但未定义GLEW_STATIC

答案 1 :(得分:0)

你自己编译过GLEW吗?

通常,名为glew32的库是动态链接,glew32s是静态的。 MinGW真的不喜欢GLEW的动态(DLL)版本,你应该避免它。由于Visual C ++和gcc的导入库函数命名约定之间存在差异,因此在GLEW站点上分发的预构建的Windows动态GLEW库将无法与MinGW一起使用(这是一个下划线的差异,但足以让生活变得非常困难)。

如果您#define GLEW_STATIC之前加入<glew.h>并链接到glew32s,那将消除动态链接库的任何潜在问题。实际上,如果您按照Nazar554演示的那样将定义添加到Makefile中,则效果最佳。

答案 2 :(得分:-2)

这个gist是我在linux中编译OpenGL项目的方法。希望它有所帮助