7

我正在使用 VC++ 2010 来处理一些 OpenGL。然而,它正在成为一种痛苦。我不断收到错误代码。

这是我正在使用的代码:

// Include standard headers
#include <stdio.h>
#include <stdlib.h>


// Include GLEW
#include <GL/glew.h>

// Include GLFW
#include <GL/glfw.h>


// Include GLM
#include <glm/glm.hpp>
using namespace glm;
int main( void ){        
    // Initialise GLFW
    if( !glfwInit() ){

            fprintf( stderr, "Failed to initialize GLFW\n" );
            return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
    {
            fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
            glfwTerminate();
            return -1;
    }

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
            fprintf(stderr, "Failed to initialize GLEW\n");
            return -1;
    }

    glfwSetWindowTitle( "Tutorial 01" );

    // Ensure we can capture the escape key being pressed below
    glfwEnable( GLFW_STICKY_KEYS );

    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.3f, 0.0f);

    do{
         // Draw nothing, see you in tutorial 2 !

         // Swap buffers
         glfwSwapBuffers();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
         glfwGetWindowParam( GLFW_OPENED ) );

// Close OpenGL window and terminate GLFW
    glfwTerminate();
    return 0;
}

以下是我在编译上述代码后从 Visual Studio 得到的错误。输出似乎是链接问题,但是,我不确定如何正确地将 glfw 要求与编辑器链接。示例错误:

Error   52  error LNK1120: 10 unresolved externals  C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\Debug\OpenGL Fun.exe OpenGL Fun
Error   42  error LNK2001: unresolved external symbol __imp__glClear@4  C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   39  error LNK2001: unresolved external symbol __imp__glClearColor@16    C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   50  error LNK2001: unresolved external symbol __imp__glGetIntegerv@8    C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(glext.obj)   OpenGL Fun
Error   45  error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4    C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_glext.obj) OpenGL Fun
Error   41  error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _glfwOpenWindow   C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(window.obj)  OpenGL Fun
Error   38  error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main   C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\Main.obj  OpenGL Fun
Error   40  error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _main    C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\Main.obj  OpenGL Fun
Error   48  error LNK2019: unresolved external symbol __imp__glGetFloatv@8 referenced in function __glfwPlatformSetWindowSize   C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   49  error LNK2019: unresolved external symbol __imp__glGetIntegerv@8 referenced in function __glfwPlatformSetWindowSize C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   51  error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function __glfwParseGLVersion  C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(glext.obj)   OpenGL Fun
Error   43  error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _createContext   C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   47  error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _destroyWindow   C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   44  error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _initWGLExtensions  C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
Error   46  error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _createWindow  C:\Users\Username\documents\visual studio 2010\Projects\OpenGL Fun\OpenGL Fun\GLFW.lib(win32_window.obj)    OpenGL Fun
4

1 回答 1

11

在解决方案资源管理器中,右键单击您的项目并选择properties. 从配置列表框中,选择“所有配置”。在左窗格中,选择Linker子树,然后input选择选项。opengl32.lib在“其他依赖项”下添加。

于 2012-07-23T02:48:54.773 回答