OpenGL GLut 与 Windows 8 64 位上的 Visual Studio 2013 链接问题

OpenGL GLut linking issues with Visual Studio 2013 on Windows 8 64bit

本文关键字:Visual Studio 2013 问题 链接 GLut Windows OpenGL      更新时间:2023-10-16

首先,我从这个来源下载了glut,http://user.xmission.com/~nate/glut.html">Nate Robins。 我把: glut32.dll into C:\Windows\SysWOW64, glut32.lib into C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib glut.h into C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL

在Visual Studio中,在C++下我创建了一个空项目,将编译器更改为64x。 我确保选择所有配置并链接opengl32.lib,glu32.lib和glut32.lib。

在"工具"-">"选项"->"VC++ 目录"->"包含文件:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include在"配置属性"→链接器→其他库目录中:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib

/************************************
* Handout: example.cpp
*
* This program is to demonstrate the basic OpenGL program structure.
* Read the comments carefully for explanations.
************************************/
#define WINDOWS     1 /* Set to 1 for Windows, 0 else */
#define UNIX_LINUX  0 /* Set to 1 for Unix/Linux, 0 else */
#if WINDOWS
#include <windows.h>
#include <GL/glut.h>
#endif
#if UNIX_LINUX
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <math.h>
float f = 0.0;
void display(void);
void my_init(void);
void reshape(int w, int h);
void idle(void);
void main(int argc, char **argv)
{
    /*---- Initialize & Open Window ---*/
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); // double-buffering and RGB color
    // mode.
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(30, 30);  // Graphics window position
    glutCreateWindow("Rectangle"); // Window title is "Rectangle"
    /*--- Register call-back functions; any order is fine ---*/
    /* Events: display, reshape, keyboard, mouse, idle, etc.
    - display: Automatically called when the window is first opened.
    Later, when the frame content needs to be changed, we need
    to call display again From the Program to re-draw the objects.
    This is essential for animation.
    - reshape: Automatically called when the window is first opened,
    or when the window is re-sized or moved by the user.
    - keyboard: Automatically called when a keyboard event occurs.
    - mouse:    Automatically called when a mouse event occurs.
    - idle:     Automatically called when nothing occurs.
    This is essential for animation.
    * Once entering the event loop, the execution control always returns to
    the event loop. When particular event occurs, the corresponding call-back
    function is called; when that call-back function finishes, control again
    goes back to the event loop, and the process is repeated.
    */
    glutDisplayFunc(display); // Register our display() function as the display 
    // call-back function
    glutReshapeFunc(reshape); // Register our reshape() function as the reshape 
    // call-back function
    // glutMouseFunc(mouse);  // for mouse 
    // glutKeyboardFunc(key); // for keyboard 
    glutIdleFunc(idle);       // Register our idle() function
    my_init();                // initialize variables
    glutMainLoop();          // Enter the event loop
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);  // clear frame buffer (also called the 
    // color buffer)
    glColor3f(0.0, 1.0, 1.0);      // draw in cyan.
    // The color stays the same until we
    // change it next time.
    glBegin(GL_POLYGON);           // Draw a polygon (can have many vertices)
    // The vertex coordinates change by different
    // values of i; see also function idle().
    glVertex2f(100, 100 + f);
    glVertex2f(200, 100 + f);
    glVertex2f(200, 300 + f);
    glVertex2f(100, 300 + f);
    glEnd();
    glFlush();         // Render (draw) the object
    glutSwapBuffers(); // Swap buffers in double buffering.
}
void my_init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0); // Use black as the color for clearing
    // the frame buffer (also called the 
    // color buffer). This produces a
    // black background.
}
void reshape(int w, int h)
{
    glViewport(0, 0, w, h);           // Viewport within the graphics window.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
}
void idle(void)
{
    f += 0.02;  // smaller number gives a slower but smoother animation
    if (f > 180.0) f = 0.0;
    glutPostRedisplay(); // or call display()
}

我的错误是

Error   17  error LNK1120: 16 unresolved externals  C:ProjectsProject1x64DebugProject1.exe Project1
Error   15  error LNK2001: unresolved external symbol _fltused  C:ProjectsProject1Project1main.obj  Project1
Error   13  error LNK2001: unresolved external symbol _RTC_InitBase C:ProjectsProject1Project1main.obj  Project1
Error   14  error LNK2001: unresolved external symbol _RTC_Shutdown C:ProjectsProject1Project1main.obj  Project1
Error   16  error LNK2001: unresolved external symbol mainCRTStartup    C:ProjectsProject1Project1LINK  Project1
Error   7   error LNK2019: unresolved external symbol __imp___glutCreateWindowWithExit referenced in function glutCreateWindow_ATEXIT_HACK  C:ProjectsProject1Project1main.obj  Project1
Error   2   error LNK2019: unresolved external symbol __imp___glutInitWithExit referenced in function glutInit_ATEXIT_HACK  C:ProjectsProject1Project1main.obj  Project1
Error   1   error LNK2019: unresolved external symbol __imp_exit referenced in function glutInit_ATEXIT_HACK    C:ProjectsProject1Project1main.obj  Project1
Error   10  error LNK2019: unresolved external symbol __imp_glutDisplayFunc referenced in function main C:ProjectsProject1Project1main.obj  Project1
Error   12  error LNK2019: unresolved external symbol __imp_glutIdleFunc referenced in function main    C:ProjectsProject1Project1main.obj  Project1
Error   3   error LNK2019: unresolved external symbol __imp_glutInitDisplayMode referenced in function main C:ProjectsProject1Project1main.obj  Project1
Error   4   error LNK2019: unresolved external symbol __imp_glutInitWindowPosition referenced in function main  C:ProjectsProject1Project1main.obj  Project1
Error   5   error LNK2019: unresolved external symbol __imp_glutInitWindowSize referenced in function main  C:ProjectsProject1Project1main.obj  Project1
Error   6   error LNK2019: unresolved external symbol __imp_glutMainLoop referenced in function main    C:ProjectsProject1Project1main.obj  Project1
Error   8   error LNK2019: unresolved external symbol __imp_glutPostRedisplay referenced in function "void __cdecl idle(void)" (?idle@@YAXXZ)   C:ProjectsProject1Project1main.obj  Project1
Error   11  error LNK2019: unresolved external symbol __imp_glutReshapeFunc referenced in function main C:ProjectsProject1Project1main.obj  Project1
Error   9   error LNK2019: unresolved external symbol __imp_glutSwapBuffers referenced in function "void __cdecl display(void)" (?display@@YAXXZ)   C:ProjectsProject1Project1main.obj  Project1

无法弄清楚我做错了什么。

您使用的是 32 位库,但您正在编译 x64 可执行文件,并且链接器无法解析这些符号。