C MinGW的带GLUT的未定义引用

C MinGW的带GLUT的未定义引用,c,windows,opengl,gcc,glut,C,Windows,Opengl,Gcc,Glut,这是我的目录: graphics/ glut.h glut32.dll glut32.lib simple.c 这是我的节目: #include <windows.h> #include <GL/gl.h> #include <GL/glext.h> #include "glut.h" void display(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(G

这是我的目录:

graphics/
    glut.h
    glut32.dll
    glut32.lib
    simple.c
这是我的节目:

#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "glut.h"


void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_POLYGON);
        glVertex2f(-0.5,-0.5);
        glVertex2f(-0.5,0.5);
        glVertex2f(0.5,0.5);
        glVertex2f(0.5,-0.5);
    glEnd();

    glFlush();
    return;
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("simple");
    glutDisplayFunc(display);
    glutMainLoop();
}
我得到以下错误:

C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x28): undefined reference to `__imp___glutInitWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x52): undefined reference to `__imp___glutCreateWindowWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x7b): undefined reference to `__imp___glutCreateMenuWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x162): undefined reference to `__imp_glutDisplayFunc'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x16b): undefined reference to `__imp_glutMainLoop'
collect2.exe: error: ld returned 1 exit status
我已经尝试了我能找到的每一个答案,我已经重新安装了MinGW,我已经重新安装了tdmcc。什么都没用,我希望有人能对此有所启发

编辑:我还将glut32.dll添加到system32中,但运气不好

您可以从网站下载使用MinGW预构建的freeglut二进制文件。您需要下载“freeglut 3.0.0 MinGW软件包”,而不是为Microsoft C构建的“freeglut 3.0.0 MSVC软件包”

include
lib
目录提取到应用程序目录中,以便使用相对路径。我已经下载并测试了;正如预期的那样,这些freeglut文件的工作方式与glut文件一样。编译命令行应为:

gcc simple.c-o MyProg-I“path/to/include/”-L“path/to/lib/”-lfreeglut-lopengl32

如果您使用64位进行编译:

gcc simple.c-o MyProg-I“path/to/include/”-L“path/to/lib/x64/”-lfreeglut-lopengl32

p、 美国。
请确保已将
freeglut.dll
文件解压缩到可执行目录中。

您可以试一试:
gcc simple.c-o MyProg-lglut32-lglu32-lopengl32-lmingw32
@ssd现在得到错误:
c:/TDM-gcc-64/bin/./lib/gcc/x86\u 64-w64-mingw32/5.1.0/../../../../../../../x86\w64-w64-mingw32/bin/bin/bin/ld.exe:找不到-lglut32
添加路径:
gcc simple.c-o MyProg-lc:\path\to\the\file\glut32-lglu32-lopengl32-lmingw32
。还有一个更正:一旦您干净地编译它,您可能需要将
glut32.dll
文件移动(或复制)到可执行路径(
\Debug
\Release
)中。
-lc:\path\to\file\glut32
部分中的
glut32
(不要在编译行中键入
.lib
扩展名)但是,您需要复制到可执行文件文件夹路径的文件是
glut32.dll
@ssd似乎找不到路径:
gcc simple.c-o MyProg-l c:\Users\Jake\Desktop\graphics\glut32-lglu32-lopengl32-lmingw32
返回错误:
c:/TDM-gcc-64/bin//lib/gcc/x86\u 64-w64-mingw32/5.1.0/../../../x86\u 64-w64-w64-mingw32/bin/ld.exe:找不到-lC:\Users\Jake\Desktop\graphics\glut32
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x28): undefined reference to `__imp___glutInitWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x52): undefined reference to `__imp___glutCreateWindowWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x7b): undefined reference to `__imp___glutCreateMenuWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x162): undefined reference to `__imp_glutDisplayFunc'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x16b): undefined reference to `__imp_glutMainLoop'
collect2.exe: error: ld returned 1 exit status