OpenGL-对GLUT的未定义引用 [英] OpenGL - Undefined references to GLUT

查看:463
本文介绍了OpenGL-对GLUT的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在使用MinGW使openGL在Windows 7上运行时遇到问题.我正在按照此处找到的步骤操作: https://www.opengl.org/wiki/MinGW

I'm having a problem getting openGL to work on Windows 7 using MinGW at the moment. I'm following the steps found here: https://www.opengl.org/wiki/MinGW

我已经安装了MinGW及其所有基本安装文件.我已经将所需的元素添加到了PATH变量中.我已经按照上面的链接中所述将GLUT文件下载并放置在正确的目录中.即便如此,使用下面的代码我仍然遇到后续错误.

I have installed MinGW and all of it's basic installation files. I have added the elements required to my PATH variable. I have downloaded and placed the GLUT files in the correct directories as described in the link above. Even so, with the below code I get the subsequent errors.

#include <GL/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 ();
}

用于编译该程序的命令是: gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32

The command used to compile this program is: gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32

错误如下(取自cmd):

The error is as follows (taken from the cmd):

C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x1c): undefined
 reference to `__glutInitWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x37): undefined
 reference to `__glutCreateWindowWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x52): undefined
 reference to `__glutCreateMenuWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x66): undefined
 reference to `_imp__glClear'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x74): undefined
 reference to `_imp__glBegin'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x8c): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xa4): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xbc): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xd4): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xdb): undefined
 reference to `_imp__glEnd'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xe2): undefined
 reference to `_imp__glFlush'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x11f): undefine
d reference to `glutDisplayFunc'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x124): undefine
d reference to `glutMainLoop'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\D
ylan\AppData\Local\Temp\cciCuMP6.o: bad reloc address 0x20 in section `.eh_frame
'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
 failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

这里的任何人都知道如何解决这些错误?我尝试卸载并重新安装MinGW,并将GLUT文件再次放置在所需目录中,但无济于事.

Anyone here have any idea how to solve these errors? I've tried uninstalling and reinstalling MinGW as well as placing the GLUT files within the required directories again but to no avail.

推荐答案

步骤1:确保您具有与编译器工具链匹配的正确构建的GLUT库.

Step 1: Make sure you have a properly built GLUT library that matches your compiler toolchain.

第2步:实际上将添加 GLUT添加到要链接的库列表中.

Step 2: Actually add GLUT to the list of libraries to link to.

GLUT是一个第三方库,它不是OpenGL的一部分(无论如何).

GLUT is a 3rd party library, that's not part of OpenGL (in any way).

这篇关于OpenGL-对GLUT的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆