problem with 'extern'

Started by
2 comments, last by Marty666 18 years, 8 months ago
Hi all, Below is my textures.cpp file. At the bottom you can find that LoadTextures() loads one texture. In main.cpp this works: extern STARTEX; in another file (universe.cpp) i get an error : unresolved external. I tried including and excluding 'textures.h' in both files but that doesn't seem to be the problem, what could it be? Thanx, Marty

#include "textures.h"


AUX_RGBImageRec *LoadBMP(char *Filename)
{
	FILE *File=NULL;							// is there a filename?
	if (!Filename){return NULL;}				// if not, return NULL
	File=fopen(Filename,"r");					// does the file exist?
	if (File) 
		{	
			fclose(File);						// then close it 
			return auxDIBImageLoad(Filename);	// and return a pointer
		} 
	return NULL;								// else return null
}


int LoadTexture(char *filename, GLuint *holder)
{
	AUX_RGBImageRec *TextureImage[1];							// storagespace for 1 texture
	memset(TextureImage,0,sizeof(void *)*1);					// clear the mem
	if (TextureImage[0] = LoadBMP(filename))					// load the file
	{
		glGenTextures(1, holder);									// create space for texture
		glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
		glBindTexture(GL_TEXTURE_2D, *holder);						// bind the loaded texture
		glTexImage2D(	GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, 
						GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // set params
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // set params
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		if (TextureImage[0])
		{
			if (TextureImage[0]->data) 
			{
				free(TextureImage[0]->data);		// free the loaded bmp
			}
			free(TextureImage[0]);					// and the memory
		}
		return 1;
	}
	return 0;
}	






GLuint STARTEX;

int LoadTextures()
{
	if (LoadTexture("Star.bmp", &STARTEX)) {return 1;}
	return 0;
}

_____ /____ /|| | || MtY | ||_____|/Marty
Advertisement
The problem is probably that the types don't match. If you declare extern STARTEX; it's implicitly an int, but you want to use an GLuint, which is unsigned. Change the declaration to extern GLuint STARTEX; and see if that works.
Unresolved external is usually a linker message that means that it could not find an instance of that variable. extern means that an instance is allocated somewhere either as a global or a static global.

As the poster above said, you need to specify the type and variable name for extern to correctly resolve it.
++Alex
Thanx! I put all my globals in stdafx.h now and include that file. I put the type there aswell and it works perfectly...
_____ /____ /|| | || MtY | ||_____|/Marty

This topic is closed to new replies.

Advertisement