我正在使用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)
它应该只能使用网站上包含的文件进行编译,但事实并非如此。
答案 0 :(得分:1)
您必须在项目中添加一些提供上述函数体的库。您可以使用源代码中的项目属性(“链接器”,“输入”,“其他依赖关系”)或#pragma
行执行此操作:
#pragma comment(lib, "libraryname.lib")
我不知道图书馆名称;它最有可能在本书的某处解释,但它可能是GLTools.lib
或GLShaderManager.lib
(或者不同的东西;你应该将这些文件放在包含文件旁边(但在lib
目录中)
编辑:你也错过了glew的lib文件(glew32.lib
)。