简体   繁体   中英

Glew undefined reference linking error

I'm running into a linking error from cmake when I attempt to build my project in CLion. I've tried what the other threads said: Putting opengl last and glu first, changing the order of my includes and setting the cmake option GLEW_STATIC but none of them have fixed it or even given different errors.

I have used glew specifically compiled for mingw32 (From https://julianibarz.wordpress.com/2010/05/12/glew-1-5-4-mingw32/ ) and I have compiled GLEW myself but I still have the same problems..

Here is my CMake file:

cmake_minimum_required(VERSION 3.2)
project(3D_prototyping)

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

if (WIN32)
else (WIN32)
  find_package (glfw3 REQUIRED)
endif (WIN32)

set(SOURCE_FILES main.cpp)

add_executable(3D_prototyping ${SOURCE_FILES})
  target_link_libraries (3D_prototyping
          ${GLFW3_LIBRARY}
          ${OPENGL_LIBRARIES}
          ${GLEW_LIBRARY}
          ${COCOA_LIBRARY} ${COREVID_LIBRARY} ${IOKIT_LIBRARY})
if (WIN32)
  target_link_libraries (3D_prototyping
          ${OPENGL_LIBRARIES} glfw3 glu32 opengl32)
endif (WIN32)

This is the error I'm getting:

"C:\Program Files (x86)\JetBrains\CLion 1.0.3\bin\cmake\bin\cmake.exe" --build C:\Users\Max\.clion10\system\cmake\generated\1d24224\1d24224\Debug --target 3D_prototyping -- -j 4
Linking CXX executable 3D_prototyping.exe
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `Z9getShaderPKcj':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:27: undefined reference to `_imp____glewCreateShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:30: undefined reference to `_imp____glewShaderSource'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:31: undefined reference to `_imp____glewCompileShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:35: undefined reference to `_imp____glewGetShaderiv'
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:75: undefined reference to `_imp____glewCreateProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:76: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:77: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:78: undefined reference to `_imp____glewBindFragDataLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:79: undefined reference to `_imp____glewLinkProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:80: undefined reference to `_imp____glewUseProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:83: undefined reference to `_imp____glewGetAttribLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:84: undefined reference to `_imp____glewVertexAttribPointer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:85: undefined reference to `_imp____glewEnableVertexAttribArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:89: undefined reference to `_imp____glewGenVertexArrays'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:90: undefined reference to `_imp____glewBindVertexArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:101: undefined reference to `_imp____glewGenBuffers'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:102: undefined reference to `_imp____glewBindBuffer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:103: undefined reference to `_imp____glewBufferData'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [3D_prototyping.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/3D_prototyping.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/3D_prototyping.dir/rule] Error 2
mingw32-make.exe: *** [3D_prototyping] Error 2
CMakeFiles\3D_prototyping.dir\build.make:86: recipe for target '3D_prototyping.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/3D_prototyping.dir/all' failed
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/3D_prototyping.dir/rule' failed
Makefile:108: recipe for target '3D_prototyping' failed

Fixed it.

Somewhere along the lines I had got glu32 which glew was using instead of the windows ones I compiled. Added a reference to glew32 and it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM