Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi there,

this is really getting on my nerves now - I've been trying for hours to get some code working that I have been learning from, but whenever I try to compile my code, all I get is the error "error LNK2001: unresolved external symbol". I've had many different errors for the vast amount of solutions that I have tried:

I have set the linker to "Windows /SUBSYSTEM:WINDOWS", as my application is a windows Application.

I'm pretty sure I selected the correct project type.

C++
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/GLAUX.H>
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")




HDC g_HDC;
float angle = 0.0f;
float legAngle[2] = {0.0f, 0.0f};
float armAngle[2] = {0.0f, 0.0f};
bool fullscreen = false;



void DrawCube(float xPos, float yPos, float zPos)
{
	glPushMatrix();
	glBegin(GL_POLYGON);

	//top face
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(0.0f, 0.0f, -1.0f);
	glVertex3f(-1.0f, 0.0f, -1.0f);
	glVertex3f(1.0f, 0.0f, 0.0f);

	//front face
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(-1.0f, 0.0f, 0.0f);
	glVertex3f(-1.0f, -1.0f, 0.0f);
	glVertex3f(0.0f, -1.0f, 0.0f); 

	//This is the right face
    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(0.0f, -1.0f, 0.0f);
    glVertex3f(0.0f, -1.0f, -1.0f);
    glVertex3f(0.0f, 0.0f, -1.0f);

    //This is the left face
    glVertex3f(-1.0f, 0.0f, 0.0f);
    glVertex3f(-1.0f, 0.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);

    //This is the bottom face
    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(0.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);

    //This is the back face
    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(-1.0f, 0.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(0.0f, -1.0f, -1.0f);

	glEnd();
	glPopMatrix();
}

//draws an arm
void DrawArm(float xPos, float yPos, float zPos)
{
	glPushMatrix();

	//sets colour to red
	glColor3f(1.0f, 0.0f, 0.0f);
	glTranslatef(xPos, yPos, zPos);

	//draws a cube
	glScalef(1.0f, 4.0f, 1.0f);
    DrawCube(0.0f, 0.0f, 0.0f);

	glPopMatrix();
}

//draw a head
void DrawHead(float xPos, float yPos, float zPos)
{

	glPushMatrix();
	//sets colour to white
	glColor3f(1.0f, 1.0f, 1.0f);
	glTranslatef(xPos, yPos, zPos);

	//crates 2x2 cube
	glScalef(2.0f, 2.0f, 2.0f);
	DrawCube(0.0f, 0.0f, 0.0f);

	glPopMatrix();

}
//draws torso
void DrawTorso(float xPos, float yPos, float zPos)
{
	glPopMatrix();
	//sets colour to blue
	glColor3f(0.0f, 0.0f, 0.0f);
	glTranslatef(xPos, yPos, zPos);

	//creates 3 x 5 x 1 cube
	glScalef(3.0f, 5.0f, 1.0f);
	DrawCube(0.0f, 0.0f, 0.0f);

	glPopMatrix();
}
//draws leg
void DrawLeg(float xPos, float yPos, float zPos)
{
	glPushMatrix();

	//Sets colour to Yellow
	glColor3f(1.0f, 1.0f, 0.0f);
	glTranslatef(xPos, yPos, zPos);

	//creates 1 x 5 x 1 cube 
	glScalef(1.0f, 5.0f, 1.0f);
	DrawCube(0.0f, 0.0f, 0.0f);
}

void DrawRobot(float xPos, float yPos, float zPos)

{
	static bool leg1 = true;
    static bool leg2 = false;
    static bool arm1 = true;
    static bool arm2 = false;

    glPushMatrix();
     
	glTranslatef(xPos, yPos, zPos);

	//location of robot
    DrawHead(1.0f, 2.0f, 0.0f);
	DrawTorso(1.5, 0.0, 0.0f);
	glPushMatrix();

}


I am well and truly stuck, and any help would be great.

Thanks all,
Nick
Posted
Updated 21-Jan-12 3:47am
v2
Comments
Richard MacCutchan 21-Jan-12 11:47am    
It might help if you told us which symbol is unresolved. I am assuming that you included the references to the GL libraries in your project.

You're missing glut32.lib from your linker list.

Add it in your configuration properties, under "Linker/Input/Additional Dependancies" or a similar place, depending on the version of VS you're using.
 
Share this answer
 
v2
Comments
Member 11849713 23-Jul-16 4:28am    
how to add that .lib file to my project
hi
this is happening because you have used some variables or functions in your code which are declared in some header file and the linker is not able to find that header file because it is not added to your references properly (for example the location of that header file changed or its path is not there in the environment settings file ). what you can do is

1).check the references of your project and see if the all files on which this project has dependency are correctly added to the references.i guess some references are missing or their locations are not proper(in which case you will see a yellow warning sign on that particular reference). for more see this
http://msdn.microsoft.com/en-us/library/wkze6zky%28v=vs.80%29.aspx[^]

2).try to build again and the output window will show which external symbols are not resolved. then check the vc++ directories "include files" in the properties and see if the there is a path to a location which has the required header file.well if not then add it and rebuild .need to do this till all symbols are resolved.
 
Share this answer
 
Hi, this is what I'm getting in my error box. I've completed the code, but I'm still getting the errors.

Quote:

Error 1 error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:\Users\Nick\Documents\Visual Studio 2010\Projects\Robot1\Robot1\main.obj


Quote:
Error 2 error LNK1120: 1 unresolved externals C:\Users\Nick\Documents\Visual Studio 2010\Projects\Robot1\Debug\Robot1.exe 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900