Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginner woes (linking) [solved]

Started by MattHughes Nov 18, 2007 at 5:10 PM 3 replies 11.5k views
Original Post
MattHughes
MattHughes
Hello, I've become comfortable with model loading, lighting, keyboard input, texturing, etc, and I'm trying to move on to GLSL. Try as I might, I cannot get my program to link properly. I'm using VC++ 2008 beta 2, but had the same problems on 2005. Here is my output:
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
1>main.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
1>main.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
1>main.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader



If I use GLee, I get the same thing:
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol _pglAttachShader
1>main.obj : error LNK2001: unresolved external symbol _pglCreateProgram
1>main.obj : error LNK2001: unresolved external symbol _pglShaderSource
1>main.obj : error LNK2001: unresolved external symbol _pglCreateShader



I put the .lib files in the VC/lib folder just as I was told. What have I done wrong? Here's the program source:
#include <windows.h>
#include <GL/GLee.h>
#include <GL/glut.h>
#include <fstream>
#include <string>

GLuint vShader, p;

const char *loadShader(char *filename) {
	std::ifstream ifs(filename);
	std::string text = "", line, nl="\n";
	if(ifs.is_open()) {
		while(!ifs.eof()) {
			std::getline(ifs, line);
			text.append(line.append(nl));
		}
	}
	return text.data();
}

static void resize(int width, int height)
{
    const float ar = (float) width / (float) height;
    
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2, 100.0);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}

static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}



static void MainLoop(void)
{
    display();
}

void setupRC() {
	GLfloat bg[] = {0.0f, 0.0f, 0.0f, 1.0f};

    glClearColor(bg[0], bg[1], bg[2], bg[3]);
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glClearStencil(0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glEnable(GL_NORMALIZE);
}

void setupShaders() {	
	vShader = glCreateShader(GL_VERTEX_SHADER);
	const char *vs = loadShader("hello.vs");
	glShaderSource(vShader, 1, &vs, NULL);
	free((void *)vs);
	p = glCreateProgram();
	glAttachShader(p, vShader);
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutInitWindowPosition(10,30);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Shaders Intro");
    glutReshapeFunc(resize);
    glutDisplayFunc(MainLoop);
    glutIdleFunc(MainLoop);

	setupRC();
	setupShaders();
    
    glutMainLoop();

    return EXIT_SUCCESS;
}



[Edited by - MattHughes on November 18, 2007 6:36:19 PM]
negatecx
negatecx
While you're including references to the objects/procedures that you call you're not actually linking the OBJ files. You have to go to project options or compiler options and add the necessary GLE object files to be linked.
scorpion007
scorpion007
You probably will need to link the LIB files that came with Glee or whatever it is. Not the .OBJ files, as there probably aren't any.
MattHughes
MattHughes
Woohoo! That did it. Thanks for the quick answers, guys.
In case anyone runs into the same problem:
In VC++, click View>Propery Pages...
Expand Configuration Properties>Linker>Input
add glew32.lib (for example) to the Additional Dependencies box.

[Edited by - MattHughes on November 18, 2007 10:35:15 PM]
negatecx
negatecx
Yeah, sorry about that. Mind typo. I meant LIB files not OBJ files.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.