3
我想設置openGL與glew和freeglut,使用this guide。錯誤LNK2019無法解析的外部符號在Visual Studio 12使用openglbook.com
我一直按照指南操作,直到第7步,但是使用本書第1章的代碼進行編譯時(我建議),我得到下面列出的錯誤。我可以看到這些錯誤發生在函數_InitWindow和_RenderFunction中,但我不知道如何解決它們。
Error 1 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 2 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 3 error LNK2019: unresolved external symbol [email protected] referenced in function _main c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 4 error LNK2019: unresolved external symbol [email protected] referenced in function _RenderFunction c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 5 error LNK2019: unresolved external symbol [email protected] referenced in function _RenderFunction c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 6 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 7 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 8 error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 9 error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 10 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 11 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 12 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 13 error LNK2019: unresolved external symbol [email protected] referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 14 error LNK1120: 13 unresolved externals c:\users\lissau\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe ConsoleApplication1
在我的main.c文件中的代碼是:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);
int main(int argc, char* argv[])
{
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
void Initialize(int argc, char* argv[])
{
InitWindow(argc, argv);
fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION)
);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if(WindowHandle < 1) {
fprintf(
stderr,
"ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(ResizeFunction);
glutDisplayFunc(RenderFunction);
}
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void RenderFunction(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
很明顯,鏈接器沒有找到freeglut庫。最好你重做這些步驟。幾分鐘前我用VS 2012做了同樣的例子,它工作正常。 –
謝謝你的回覆。然而,作爲一個初學者,我沒有找到明顯的解決方案,並從大量關於錯誤LNK2019的問題來看,我認爲我不是唯一的解決方案。 – Attaque