Error in using static map

I am a C# .NET programmer who has recently switched to c++, and thus my understanding on some things could be a little fuzzy...

i am attempting to create a static STL map for the purpose of keeping track of which textures i have already loaded into video memory. It needs to store a string, and a GLuint, and after reading some things i managed to get that working, but when i tried to make it a static member of my texture loading class, everything goes haywire... so here is my code, and my error, any help would be greatly appreciated...

Header:

#ifndef __TEXTURELOADER_H__
#define __TEXTURELOADER_H__

#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <stdio.h>
#include <Carbon/Carbon.h>
#include <string>
#include <map>

#include "TGAHeader.h"
#include "Texture.h"
#include "TGA.h"

class TextureLoader
{
private:
static bool LoadTGA(Texture * texture, const char * filename);
static bool LoadUncompressedTGA(Texture *, const char * filename, FILE *);
static bool LoadCompressedTGA(Texture *, const char * filename, FILE *);
static std::map<std::string, GLuint> textures;
public:
static GLuint LoadTexture(std::string filename);

};
#endif

code for LoadTexture (this is where the error occurs i think) :

GLuint TextureLoader::LoadTexture(std::string filename)
{
Texture tex; //create Texture structure to load into
GLuint texID; //greate ID for texture once loaded in OpenGL

if(textures.find(filename) != textures.end())
{
return textures.find(filename)->second;
}

if(LoadTGA(&tex, filename.c_str())) //Try to load texture from file, if sccuessful, load into OpenGl
{
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, tex.width, tex.height, 0, tex.type, GL_UNSIGNED_BYTE, tex.imageData);
}
free(tex.imageData);
textures[filename] = texID;
return texID; //return OpenGl Texture ID so that we can use it
}
All the code compiles fine, and the application launches, but then i get this:

ZeroLink: unknown symbol '__ZN13TextureLoader8texturesE'

SimpleGame has exited due to signal 6 (SIGABRT).

Again, my "c++-fu" is very weak so this could be something very simple... Thanks for taking the time to read!!

Could you isolate the bug enough to create a compilable module of code with a main and everything necessary to build in the VC++ IDE with the following headers?
1
2
3
4
5
6
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <iostream>
#include <stdio.h>
#include <math.h> 

Or can we download your entire program from somewhere?
static member variables of a class have to be defined outside the clas somewhere - a class declaration is not enough.
E.g

1
2
3
4
5
6
7
8
//header file
class myclass
{
    static int  someint;
};

//cpp file
int myclass::someint = 5 //initialise as appropriate 


But I would have thought the compiler would have picked up on that.
To be sure - just supply the code as wretch suggested.
Last edited on
Topic archived. No new replies allowed.