C++ 加载OpenGL项目的.obj文件时发生LNK2019错误

C++ 加载OpenGL项目的.obj文件时发生LNK2019错误,c++,opengl,lnk2019,C++,Opengl,Lnk2019,我想在OpenGL中为我的房间建模,当我创建第一个对象并学习一些教程时,在Visual Studio 2013 Professional应用程序中加载该对象时,我发现以下错误: Warning 1 warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplic

我想在OpenGL中为我的房间建模,当我创建第一个对象并学习一些教程时,在Visual Studio 2013 Professional应用程序中加载该对象时,我发现以下错误:

Warning 1   warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   2   error LNK2019: unresolved external symbol "float __cdecl glmUnitize(struct _GLMmodel *)" (?glmUnitize@@YAMPAU_GLMmodel@@@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)   d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   3   error LNK2019: unresolved external symbol "void __cdecl glmFacetNormals(struct _GLMmodel *)" (?glmFacetNormals@@YAXPAU_GLMmodel@@@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)  d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   4   error LNK2019: unresolved external symbol "void __cdecl glmVertexNormals(struct _GLMmodel *,float)" (?glmVertexNormals@@YAXPAU_GLMmodel@@M@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z) d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   5   error LNK2019: unresolved external symbol "struct _GLMmodel * __cdecl glmReadOBJ(char *)" (?glmReadOBJ@@YAPAU_GLMmodel@@PAD@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   6   error LNK2019: unresolved external symbol "void __cdecl glmDraw(struct _GLMmodel *,unsigned int)" (?glmDraw@@YAXPAU_GLMmodel@@I@Z) referenced in function "void __cdecl drawModel(struct _GLMmodel * *,char *,unsigned int)" (?drawModel@@YAXPAPAU_GLMmodel@@PADI@Z)    d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\OpenGLApplication.obj    OpenGLApplication
Error   7   error LNK1120: 5 unresolved externals   d:\Egyetem\Semester 5\Graphic processing systems\Project\OpenGLApplication\Debug\OpenGLApplication.exe  OpenGLApplication
这是我的代码,非常简单,只是加载和可视化对象:

// OpenGLApplication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "glut.h"
#include "glm.h"
#include <gl/gl.h>
#include <math.h>

int screen_width=1366;
int screen_height=768;
GLMmodel *bed;

void initOpenGL()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glShadeModel(GL_SMOOTH);
    glViewport(0, 0, screen_width, screen_height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (GLfloat)screen_width/(GLfloat)screen_height, 1.0f, 1000.0f);
    glEnable(GL_DEPTH_TEST);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
}

void drawModel(GLMmodel **pmodel, char*filename, GLuint mode)
{
    if (!*pmodel){
        *pmodel = glmReadOBJ(filename);
        if (!*pmodel){
            exit(0);
        }
        glmUnitize(*pmodel);
        //generate facet normal vectors for model
        glmFacetNormals(*pmodel);
        //generate vertex normal vectors (called after generating facet normals)
        glmVertexNormals(*pmodel, 90.0);
    }
    glmDraw(*pmodel, mode);
}


void renderScene(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, -10.0, 0.0, 1.0, 0.0);

    glPushMatrix();
        drawModel(&bed, "castle.obj", GLM_NONE | GLM_FLAT);
    glPopMatrix();

    glutSwapBuffers();
}

void changeSize(int w, int h)
{
    screen_width=w;
    screen_height=h;

    if(h == 0)
        h = 1;

    float ratio = 1.0*w/h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, w, h);
    gluPerspective(45.0f, ratio, 1.0f, 1000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0f, 0.0f, 50.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
}

void processNormalKeys(unsigned char key, int x, int y)
{

    switch(key)
    {
        case 't':
            //process
            glutPostRedisplay();
            break;
    }


}

int main(int argc, char* argv[])
{
    //Initialize the GLUT library
    glutInit(&argc, argv);
    //Set the display mode
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    //Set the initial position and dimensions of the window
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(screen_width, screen_height);
    //creates the window
    glutCreateWindow("First OpenGL Application");
    //Specifies the function to call when the window needs to be redisplayed
    glutFullScreen();
    glutDisplayFunc(renderScene);
    //Sets the idle callback function
    glutIdleFunc(renderScene);
    //Sets the reshape callback function
    glutReshapeFunc(changeSize);
    //Keyboard callback function
    glutKeyboardFunc(processNormalKeys);
    //Initialize some OpenGL parameters
    initOpenGL();
    //Starts the GLUT infinite loop
    glutMainLoop();
    return 0;
}
我在谷歌或此处所想到或发现的可能错误,并没有改变任何事情:

试图设置项目->链接器->常规->启用增量链接=否

glm.cpp、glm.h、glut.h、glut32.dll、glut32.lib、StdAfx.h、StdAfx.cpp位于项目目录中

对象及其.mtl文件位于项目目录中


有人能帮我找出为什么我不能加载这个对象吗?

我的猜测是glm库也应该包含进来,现在尝试一下,但还是一样的。可能是缺少一些.dll,或者OpenGL库与Windows 8.1不兼容吗?我怀疑在这种情况下,是否有一个名为GLM的实际库可以链接到。有一个模板化的C++数学库,叫做GLM,但这是100%行内联,最后用后缀HPP结束。您实际的问题很可能只是您没有将glm.cpp作为项目构建过程的一部分。它在项目目录中这一事实在Visual Studio中并不意味着什么——你需要它在项目的源文件列表中。你做对了。这就是问题所在。它存在于项目目录中,但未添加到解决方案中。当然,我说的是我在GLM包中找到的那些.hpp文件,但这些都没用。谢谢你的快速回答。