GLEW链接错误。错误LNK2019

脾气暴躁

我正在使用Visual Studio 2013,并且是C ++的新手。我安装了GLEW和freeglut。我尝试构建我的文件“ main.c”,并且收到以下消息:

1>------ Build started: Project: testGlut1, Configuration: Debug Win32 ------
1>  main.c
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit@0 referenced function _Initialize
1>main.obj : error LNK2019: unresolved external symbol __imp__glewGetErrorString@4 referenced in function _Initialize
1>C:\Users\User\documents\visual studio 2013\Projects\testGlut1\Debug\testGlut1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我读过一个类似的问题,但是该解决方案对我不起作用,实际上,没有任何变化。另外,我只有2个未解决的外部问题,而上述问题显示了16个未解决的外部问题。为什么?为什么要这样隔离这两个错误?

我的程序的源代码:

#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)
            );
        exit(EXIT_FAILURE);
    }

    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);
}

这是我的其他依赖项:

我的其他依赖

这是MyDocuments中的Debug文件夹:

Debug_folder

脾气暴躁

链接文件的OS版本之间根本不兼容。我以为该进程使用SysWOW64来搜索GLUT和GLEW的DLL文件,因为我的操作系统是Windows 64位。无论如何,我使用了Dependecy Walker 2.2工具来跟踪先前创建的.exe文件,并了解到我的操作系统正在C:\ Windows \ System32中搜索DLL文件。烦人的事改变了一切。出于一天半的搜索无奈,我进入了C:\ Program Files(x86)\ Windows Kits \ 8.1 \ Lib \ winv6.3 \ um \ x86并交换了glew32.lib(64 -位)(适用于glew32.lib(32位)),瞧,我可以运行我的程序而不会出现任何错误。由于我不是专家,甚至没有C编程经验,所以只能说这是的临时解决方案问题。我不确定为什么该程序通过C:\ Windows \ System32而不是C:\ Windows \ SysWOW64进行搜索。但是,我希望该解决方案可以帮助那些在尝试使用GLEW,GLUT和Microsoft Visual Studio时遇到神秘的链接器错误消息的人。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

xDispatch LNK2019链接器错误未解决的外部

VS2013 VC ++ libcurl LNK2028 LNK2019链接错误

Visual Studio 2013 dll导出链接错误(LNK2019 / LNK1120)

单个文件代码中的链接器错误 LNK2019 和 LNK1120

Visual Studio 2013错误LNK2019

Storyboard_Completed事件产生链接器工具错误LNK2019错误

安装了MPI,但仍然出现链接器错误LNK2019

位于单个文件中的两个类的链接器错误(LNK2019)

Linux 和 macOS 很好,但 Windows 构建会引发链接器错误 LNK2019

链接 CPP 文件进行测试时出现 LNK2019 错误

LNK2019错误(无法解析的外部符号)将SQLite链接到DLL

与Muiload.lib链接时的VS2015:LNK2019错误

错误 LNK2019:无法解析的外部符号(libJPEG 编译和链接)

C++ LNK2019 错误,lib 已添加到链接器

错误编译简单程序错误LNK2019

错误:LNK2019:Qt中无法解析的外部符号

错误 LNK2019:未解析的外部符号静态库

错误LNK2019:无法解析的外部符号“ public:__thiscall

Visual Studio的LNK2019错误-无法解析的外部符号

问题:“错误LNK2019:无法解析的外部符号”

从模板派生时出现LNK2019错误

错误LNK2019:无法解析的外部符号“ public:

LNK2019:单调中未解决的错误

错误LNK2019:无法解析的外部符号:: FindWindow()函数

编译OpenCL文件时出现许多LNK2019错误

主函数C函数错误LNK2019

opencv 3:CVcreatebutton 给出 LNK2019 错误

Visual Studio系列如何自己解决LNK2019错误

Visual Studio 2012错误LNK2019:无法解析的外部符号,与正在运行的静态库链接