1

我正在使用 Superbible 第 5 版,我已经遇到了第一个程序的问题。通过添加 Windows.h 并删除 #define FREEGLUT_STATIC 行,我已经能够解决很多问题,但是我无法克服我现在遇到的链接器错误。

#include <Windows.h>
#include <GLTools.h>
#include <GLShaderManager.h>

#include <gl\glew.h>
#include <gl\glut.h>

GLBatch triangleBatch;
GLShaderManager shaderManager;

void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}

void SetupRC()
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

shaderManager.InitializeStockShaders();

GLfloat vVerts[] = 
{ 
    -0.5f, 0.0f, 0.0f,
    0.5f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f
};

triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}

 void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();

glutSwapBuffers();
}

int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);

GLenum err = glewInit();
if(GLEW_OK != err)
{
    fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
    return 1;
}

SetupRC();

glutMainLoop();
return 0;
}

这些是我得到的错误:

1>triangle test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::End(void)" (?End@GLBatch@@QAEXXZ) referenced in function "void __cdecl SetupRC(void)" (?SetupRC@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::Begin(unsigned int,unsigned int,unsigned int)" (?Begin@GLBatch@@QAEXIII@Z) referenced in function "void __cdecl SetupRC(void)" (?SetupRC@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: bool __thiscall GLShaderManager::InitializeStockShaders(void)" (?InitializeStockShaders@GLShaderManager@@QAE_NXZ) referenced in function "void __cdecl SetupRC(void)" (?SetupRC@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::CopyVertexData3f(float (*)[3])" (?CopyVertexData3f@GLBatch@@QAEXPAY02M@Z) referenced in function "public: void __thiscall GLBatch::CopyVertexData3f(float *)" (?CopyVertexData3f@GLBatch@@QAEXPAM@Z)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall GLBatch::Draw(void)" (?Draw@GLBatch@@UAEXXZ) referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: int __cdecl GLShaderManager::UseStockShader(enum GLT_STOCK_SHADER,...)" (?UseStockShader@GLShaderManager@@QAAHW4GLT_STOCK_SHADER@@ZZ) referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol _glewGetErrorString referenced in function _main
1>triangle test.obj : error LNK2019: unresolved external symbol _glewInit referenced in function _main
1>triangle test.obj : error LNK2019: unresolved external symbol "void __cdecl gltSetWorkingDirectory(char const *)" (?gltSetWorkingDirectory@@YAXPBD@Z) referenced in function _main
1>triangle test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLBatch::GLBatch(void)" (??0GLBatch@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'triangleBatch''(void)" (??__EtriangleBatch@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLShaderManager::GLShaderManager(void)" (??0GLShaderManager@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'shaderManager''(void)" (??__EshaderManager@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall GLBatch::~GLBatch(void)" (??1GLBatch@@UAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'triangleBatch''(void)" (??__FtriangleBatch@@YAXXZ)
1>triangle test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLShaderManager::~GLShaderManager(void)" (??1GLShaderManager@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'shaderManager''(void)" (??__FshaderManager@@YAXXZ)

它应该能够仅使用网站中包含的文件进行编译,但事实并非如此。

4

1 回答 1

1

您必须将一些库添加到提供上述功能体的项目中。您可以使用项目属性(“Linker”、“Input”、“Additional Dependencies”)或#pragma源代码中的任何位置来执行此操作:

#pragma comment(lib, "libraryname.lib")

我不知道图书馆名称;它很可能在书中某处进行了解释,但它可能是GLTools.libor GLShaderManager.lib(或不同的东西;您应该将这些文件放在包含文件旁边的某个位置(但在一个lib目录中)。

编辑:您也缺少 glew 的 lib 文件(glew32.lib)。

于 2012-06-21T21:14:58.890 回答