1
votes

I'm trying to do the openGLbook.com tutorial. I get this common error:

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

I've downloaded the latest 64-bit binaries for GLEW from glew.sourceforge.net, and copied them into their corresponding locations within C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A. I've also downloaded the latest freeglut files and did the same.

I'm using VS 2010. The following are the settings I've changed (based on other threads and forums):

1) Properties > VC++ Directories........ added the "include" folder that contains glew.h and freeglut.h

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

I really don't understand why it still isn't linking the libraries properly. I should also note that I'm working from a different drive than the C drive. Could that have an effect even though I'm linking everything to its proper folder in the properties?

edit: forgot to post the actual code, here it is:

#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);
}
3
"like the 4 other OpenGL tutorials I've attempted in the past month or so, I can't even get the thing started" If you've tried 5 separate download packages and can't get any of them working, perhaps the problem is your machine and familiarity with your build system, not what any of them do.Nicol Bolas
The problem is obviously my lack of understanding, I'm sure all of the things I've tried work just fine for someone that understands the core concepts. Like I said, I'm new programming. Everything I learn is totally new. First I tried these tutorials: arcsynthesis.org/gltut, but building the libraries and so on was just too much for me to handle. Tried finding some simpler tutorials but a lot of them dealt with GLUT, which I have no desire to learn since most people seem to think it's obsolete now. What am I missing here? What could my problem be?EindacorDS
Your problem is that you're too new to be working with this kind of stuff. The only way I could help you is if I were at your machine and walked you through it. You need to take some time to get familiar with your tools. Before you get into OpenGL, and graphics programming in general, you should know your build tools. You should know what a library is and know how to build and link one. You should know how to make VS projects and programs built from multiple files. Graphics programming is just not a beginner-level subject. Take your time and get it right.Nicol Bolas
Think you're right. Any chance you have a suggestion on where to start with these things? Is there a definitive resource for learning the ins and outs of VS?EindacorDS
@user I wouldn't bother searching around for VS specific material. Rather, focus on learning concepts which are independent of platform/compiler specifics. Also, if you're linear algebra skills are rusty or you've never studied it before, I'd brush up on that. In a nutshell, there are no shortcuts; i had to learn this the hard way. Good luck :-)zeboidlund

3 Answers

11
votes

I'm sorry if you've already figured this out. I also didn't take the time to read through the comments. However, you are linking to glew32s.lib which is the static library but you do not have #define GLEW_STATIC at the top of your code with your includes.

Try that. I'm pretty confident that's your problem. I tried commenting out that line in my code and got similar errors.

2
votes

Well, MS compilers can give you link errors for a lot of reasons. One is, not linking with the library you need to! There is a linker option (/VERBOSE) that lists all the link libraries it is searching when it tried to link. Turn that on and make sure it's actually searching the GLEW libraries where you have them.

Another possibility is that you're using the wrong GLEW library. MS intentionally changes the way function/method names are encoded between compiler versions so you can't link a VC++ 2008 library into a VC++ 2010 compiled app. Similarly you can't link a 64-bit library into a 32-bit build. You will receive "unresolved external symbol" errors like this.

You can "unmangle" the "mangled" name you see there: _imp_glewGetErrorString@4

and tell whether it's a 64-bit or 32-bit library based on the extra underscores and such.

http://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B_Name_Mangling

but that's hard for beginners.

My guess is you aren't linking with the library you think you are.

-1
votes

I just come across this problem recently. I'm running Windows 8, compiling GLEW program using VS Express 2012 (I'm new to this IDE since I have been using VC++ 6.0 for so long). Usually this problem is due to the missing DLL files, I resolve it by copying the glew32.dll from <Glew_HOME>\bin\Release\Win32 (not the x64 version) into directory C:\Windows\SysWOW64. It could be best if I know how I could link the DLL resources statically with the EXE, so that I'm no longer required to depends on system's resource.