gpt4 book ai didi

opengl - GLEW 链接错误

转载 作者:行者123 更新时间:2023-12-05 08:28:25 28 4
gpt4 key购买 nike

我正在尝试做 openGLbook.com 教程。我收到这个常见错误:

    1>------ Build started: Project: OpenGL Startup, Configuration: Debug Win32 ------
1>Build started 1/25/2013 8:18:16 PM.
1>InitializeBuildStatus:
1> Touching "Debug\OpenGL Startup.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol __imp__glewGetErrorString@4 referenced in function _Initialize
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _Initialize
1>J:\Coding Projects\OpenGL 3.3 Tutorial\OpenGL Startup\Debug\OpenGL Startup.exe : fatal error LNK1120: 2 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.07
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我已经从 glew.sourceforge.net 下载了 GLEW 的最新 64 位二进制文​​件,并将它们复制到 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A 中的相应位置。我还下载了最新的 freeglut 文件并做了同样的事情。

我使用的是 VS 2010。以下是我更改的设置(基于其他主题和论坛):

1) Properties > VC++ Directories........ 添加了包含 glew.h 和 freeglut.h 的“include”文件夹

2) Properties > Linker > Input > Additional Dependencies..... 添加了 glew32.lib, freeglut.lib, glew32mx.lib, glew32mxs.lib, glew32s.lib

我真的不明白为什么它仍然没有正确链接库。我还应该注意,我在与 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;

unsigned FrameCount = 0;

void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);
void TimerFunction(int);
void IdleFunction(void);

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

glutMainLoop();

exit(EXIT_SUCCESS);
}

void Initialize(int argc, char* argv[])
{
GLenum GlewInitResult;

InitWindow(argc, argv);

GlewInitResult = glewInit();

if (GLEW_OK != GlewInitResult) {
fprintf(
stderr,
"ERROR: %s\n",
glewGetErrorString(GlewInitResult)
);
}

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);
glutIdleFunc(IdleFunction);
glutTimerFunc(0, TimerFunction, 0);
}

void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}

void RenderFunction(void)
{
++FrameCount;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glutSwapBuffers();
glutPostRedisplay();
}


void IdleFunction(void)
{
glutPostRedisplay();
}

void TimerFunction(int Value)
{
if (0 != Value) {
char* TempString = (char*)
malloc(512 + strlen(WINDOW_TITLE_PREFIX));

sprintf(
TempString,
"%s: %d Frames Per Second @ %d x %d",
WINDOW_TITLE_PREFIX,
FrameCount * 4,
CurrentWidth,
CurrentHeight
);

glutSetWindowTitle(TempString);
free(TempString);
}

FrameCount = 0;
glutTimerFunc(250, TimerFunction, 1);
}

最佳答案

如果您已经弄明白了,我很抱歉。我也没有花时间阅读评论。但是,您正在链接到静态库 glew32s.lib,但您的代码顶部没有包含您的包含项的#define GLEW_STATIC。

试试吧。我很确定那是你的问题。我尝试在我的代码中注释掉该行,但遇到了类似的错误。

关于opengl - GLEW 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14532917/

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