Home » Community » Forums » For Beginners » Beginner woes (linking) [solved]
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Beginner woes (linking) [solved]
Post New Topic  Post Reply 
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]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1009   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Yeah, sorry about that. Mind typo. I meant LIB files not OBJ files.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: