Jump to content
  • Advertisement
Sign in to follow this  
Marty666

problem with 'extern'

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanx! I put all my globals in stdafx.h now and include that file. I put the type there aswell and it works perfectly...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!