Linker Error 2019 - OpenGL Material Class

So far I've been working through a 3DBUZZ OpenGL vtm's without any problems untill now, currently I am having a few problems with my OpenGL Texture Class.

All I'm trying to do is load in the data from a TGA file.

I've been trying to work out what is wrong for the past few days and I still can't find a solution to it.

error LNK2019: unresolved external symbol.


I've included my .h + .cpp, Any help would be great, Thank you.

texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#ifndef TEXTURE_H
#define TEXTURE_H
#include <string>
#include <vector>
#include <fstream>
using std::string;
using namespace std;


#ifdef WIN32
	#define WIN32_LEAN_AND_MEAN
	#include <windows.h>
#endif

#if defined(__APPLE__) && defined(__MACH__)
	#include <OpenGL/gl.h>
	#include <OpenGL/glu.h>
#else
	#include <GL/glu.h>
	#include <GL/gl.h>
#endif

struct TGA_Header
{
	GLubyte		ID_Length;
	GLubyte		ColorMapType;
	GLubyte		ImageType;
	GLubyte		ColorMapSpecification[5];
	GLshort		xOrigin;
	GLshort		yOrigin;
	GLshort		imageWidth;
	GLshort		imageHeight;
	GLubyte		pixelDepth;
};

class Texture
{
public:
	Texture( string filename, string name = " ");
	~Texture();

public:
	unsigned char		*imageData;
	unsigned int		bpp; //bits per pixel
	unsigned int		width;
	unsigned int		height;
	unsigned int		texID;

	string name;

	static vector<Texture *> textures;

private:
	bool loadTGA( string filename);
	bool createTexture( unsigned char *imageData, int width, int height, int type);
};

#endif 


texture.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "texture.h"

vector<Texture *>Texture::textures;

Texture::Texture(string in_filename, string in_name)
{
	imageData = NULL;

	loadTGA(in_filename);

	name = in_name;

	textures.push_back(this);
}

Texture::~Texture()
{
	for ( vector<Texture *>::iterator it = textures.begin(); it != textures.end(); it++)
	{
		if ( (*it) == this )
		{		
			textures.erase(it);
		}
	}

	if (imageData)
	{
		delete imageData;
	}
}

bool Texture::loadTGA(string filename)
{
	TGA_Header TGAheader;
	
	ifstream file( filename.data(), std::ios_base::binary );

	if ( file.is_open() )
	{
		return false;
	}


	if (!file.read( (char * )&TGAheader, sizeof(TGAheader)))
	{
		return false;
	}
	

	if ( TGAheader.ImageType != 2)
	{
		return false;
	}


	width = TGAheader.imageWidth;
	height = TGAheader.imageHeight;
	bpp = TGAheader.pixelDepth;

	if ( width <=0 || height <=0 || (bpp != 24 && bpp != 32) )
	{
		return false;
	}

	GLuint type = GL_RGBA;
	if ( bpp == 24 )
	{
		type = GL_RGB;
	}

	GLuint bytesPerPixel = bpp / 8;
	GLuint imageSize = width * height * bytesPerPixel;

	imageData = new GLubyte[imageSize];

	if ( imageData == NULL)
	{
		return false;
	}

	if (!file.read( ( char*)imageData, imageSize))
	{
		delete imageData;

		return false;
	}
	//Concerts BGR--> TO RGB;
	for ( GLuint i = 0; i < (int)imageSize; i+=bytesPerPixel)
	{
		GLuint temp = imageData[i];
		imageData[i] = imageData[i+2];
		imageData[i+2] = temp;
	}

	createTexture(imageData, width, height, type);

	//No problems

	return true;

}

bool Texture::createTexture ( unsigned char *imageData, int width, int height, int type)
{
	glGenTextures(1, &texID);
	glBindTexture(GL_TEXTURE_2D, texID);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	

	glTexImage2D(GL_TEXTURE_2D,0,type, width, height, 0 , type, GL_UNSIGNED_BYTE, imageData);
	return true;
}
Is that really the whole error message? unresolved external symbol errors usually say what the symbol is..
Anyway, unresolved external symbol means that you're trying to use some undefined function.
By the way, are you using VC++ ?
Using VC 2005.

The whole error code is :

1>Linking...

1>texture.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class Texture * const & __thiscall std::_Vector_const_iterator<class Texture *,class std::allocator<class Texture *> >::operator*(void)const " (??D?$_Vector_const_iterator@PAVTexture@@V?$allocator@PAVTexture@@@std@@@std@@QBEABQAVTexture@@XZ)

1>C:\Programming\SDL_texture\Debug\SDL_demo.exe : fatal error LNK1120: 1 unresolved externals

Seems it didn't want to copy and paste the first time :)
Are you building a release or debug version of the application? If release, could you build the debug version & let us know if you get the same linker error?
The errors are from the debug version.

Just on a note: If anyone else has got a working version of these files from the VTM's Is there any chance I could get a copy then I can compare the two and try solve it. Cheers
Last edited on
So with some messing around I've narrowed the problem down to 4 lines of code, and I am guessing that's because the other lines are dependant on the 1st line working.

in the "texture.cpp"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Texture::Texture(string in_filename, string in_name)
{
	imageData = NULL;

	loadTGA(in_filename);

	name = in_name;

	//textures.push_back(this); //<---- Uncommenting these lines causes the linker error
}

Texture::~Texture()
{
	//for ( vector<Texture *>::iterator it = textures.begin(); it != textures.end(); it++) //<---- Uncommenting these lines causes the linker error.
	{
		//if ( (*it) == this ) //<---- Can't work without iterator it.
		{		
			//textures.erase(it); //<---- Same as above.
		}
	}

	if (imageData)
	{
		delete imageData;
	}
}


I think it's the line

textures.push_back(this);

causing the error.
I've found the problem :

C/C++ -> Preprocessor -> _DEBUG;

Something to do with the mixing debug and release versions I think.

Topic archived. No new replies allowed.