gpt4 book ai didi

visual-studio - 使用 openglbook.com 在 Visual Studio 12 中出现错误 LNK2019 无法解析的外部符号

转载 作者:行者123 更新时间:2023-12-04 06:06:35 26 4
gpt4 key购买 nike

我正在尝试使用 glew 和 freeglut 设置 openGL,使用 this guide .

我一直按照指南进行到第 7 步,但是当使用本书第 1 章中的代码(按照建议)进行编译时,出现下面列出的错误。我可以看到错误发生在_InitWindow 和_RenderFunction 函数中,但我不知道如何解决它们。

Error   1   error LNK2019: unresolved external symbol __imp__glutInitWindowSize@8 referenced in function _InitWindow     c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 2 error LNK2019: unresolved external symbol __imp__glutInitDisplayMode@4 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 3 error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function _main c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 4 error LNK2019: unresolved external symbol __imp__glutPostRedisplay@0 referenced in function _RenderFunction c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 5 error LNK2019: unresolved external symbol __imp__glutSwapBuffers@0 referenced in function _RenderFunction c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 6 error LNK2019: unresolved external symbol __imp__glutReshapeFunc@4 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 7 error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 8 error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8 c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 9 error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4 c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 10 error LNK2019: unresolved external symbol __imp__glutSetOption@8 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 11 error LNK2019: unresolved external symbol __imp__glutInitContextVersion@8 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 12 error LNK2019: unresolved external symbol __imp__glutInitContextFlags@4 referenced in function _InitWindow c:\Users\Lissau\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
Error 13 error LNK2019: unresolved external symbol __imp__glutInitContextProfile@4 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();
}

最佳答案

在多次重做教程的步骤但没有成功后,我去自由式寻找答案(教程中没有)。

我的问题是附加库目录路径未设置为我的 lib 文件的路径。通过右键单击您的项目来更改此设置,从下拉列表中选择“所有配置”,然后转到链接器->常规->附加库目录->编辑。在我的例子中,我将它设置为“C:\Program Files %28x86%29\Microsoft SDKs\Windows\v8.0A\Lib”。

关于visual-studio - 使用 openglbook.com 在 Visual Studio 12 中出现错误 LNK2019 无法解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15971519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com