GLEW库不能链接到CodeBlocks(MinGW)

它列出的未定义的引用清楚地设置在“glew.h”中。 我已经在连接器中包含库,包含在search目录中,并且已经将glew32.dll复制到系统registry中(以及许多其他地方 – MinGW目录内的几个位置以及debugging目录)。 我在他们的网站上使用了最新版本的GLEW,尽pipecodeBlocks和freeGlut在十月/十一月份被下载了。 我试图按照OpenGL / Glut的快速教程。

显然,debugging器没有正确地链接库/头,但我不明白为什么 – 我到处search,还有一些关于使minGW静态,我不太明白,但它听起来像它doesn为了工作,不需要做。

错误面食:

-------------- Build: Debug in Window Tutorial (compiler: GNU GCC Compiler)--------------- mingw32-g++.exe -LC:\glew-1.10.0\include\GL -LC:\freeglut\include\GL -LC:\freeglut\lib -LC:\glew-1.10.0\lib\Release\Win32 -o "bin\Debug\Window Tutorial.exe" obj\Debug\main.o C:\glew-1.10.0\lib\Release\Win32\glew32.lib C:\glew-1.10.0\lib\Release\Win32\glew32s.lib C:\freeglut\lib\glut32.lib C:\freeglut\lib\libfreeglut.a C:\freeglut\lib\libfreeglut_static.a obj\Debug\main.o: In function `display': C:/Users/CNOVDM/Other/codeBlocks/Swiftless/Window/Window Tutorial/main.c:5: undefined reference to `glClearColor@16' C:/Users/CNOVDM/Other/codeBlocks/Swiftless/Window/Window Tutorial/main.c:6: undefined reference to `glClear@4' C:/Users/CNOVDM/Other/codeBlocks/Swiftless/Window/Window Tutorial/main.c:7: undefined reference to `glLoadIdentity@0' C:/Users/CNOVDM/Other/codeBlocks/Swiftless/Window/Window Tutorial/main.c:9: undefined reference to `glFlush@0' collect2.exe: error: ld returned 1 exit status Process terminated with status 1 (0 minutes, 4 seconds) 4 errors, 0 warnings (0 minutes, 4 seconds) 

代码:

 #include <glew.h> #include <glut.h> void display (void) { glClearColor(1.0f, 0.0f, 0.0f, 1.0f); //Clear the background of our window to red glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on) glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations glFlush(); // Flush the OpenGL buffers to the window } int main (int argc, char **argv) { glutInit(&argc, argv); // Initialize GLUT glewInit(); glutInitDisplayMode(GLUT_SINGLE); //Set Up a basic Display Buffer (only single buffered for now) glutInitWindowSize(500,500); // Set the width and height of the window glutInitWindowPosition(100,100); // set the position of the window glutCreateWindow("My First OpenGL Window"); // Set the title for the window glutDisplayFunc(display); // Tell GLUT to use the method "display" for rendering glutMainLoop(); // Enter GLUT's main loop } 

我想你忘了链接到lib文件。

阅读手册1.11.13 。

如果使用x64系统,则应将glew32.dll放在lib\release\x64System32 ,另一个放在lib\release\Win32SysWOW64

这个链接将帮助你理解它。

据我所知,即使你连接到glew,你仍然需要链接到GL。 尝试添加-lopengl32