Question

I'm using Visual Studio 2013 and am new to C++. I installed GLEW and freeglut. I try to build my file "main.c", and I receive this:

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 ==========

I read through a similar issue, however the solution didn't work for me, in fact, nothing changed. Also, I only have 2 unresolved externals whereas the aforementioned issue showed 16 unresolved externals. Why? Why are those two errors isolated as such?

The source code for my program:

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

Here are my additional dependencies:

My additional Dependencies

Here is the Debug folder in MyDocuments:

Debug_folder

Was it helpful?

Solution

There were simply incompatibilities between the OS versions of the linked files. I thought that the process was using SysWOW64 to search for the DLL files of GLUT and GLEW since my OS is Windows 64-bit. Anyway, I used the tool, Dependecy Walker 2.2, to track an previously created .exe file and learned that my OS was searching C:\Windows\System32 for the DLL files. That changed everything, annoyingly. Out of frustration in having searched for answers for over a day and a half, I went into C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86 and swapped the glew32.lib (64-bit) for glew32.lib (32-bit), and voila, I can run my program without any errors. Since I am not an expert, or even practiced in C programming, I can only say that this is a temporary solution for my problem. I'm not sure why the program searches through C:\Windows\System32 rather than C:\Windows\SysWOW64. But, I hope that this solution helps those whom have exprienced a mysterious linker error messages when trying to use GLEW, GLUT, and Microsoft Visual Studio.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top