Sign in to follow this  

Linker Error's With Texture Manager

This topic is 2540 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

Well I need some help with my project. I am trying to make a texture manager and I have all the textures defined in the TextureManager.h and all the Images assigned to the textures in the TextureManager.cpp.

I then have a class where I try to bind a texture but then it gives me the linker error LNK2005. It says its already defined.. So can someone help me?

Here are the files that I think are causing the problem:

Main: http://pastebin.com/4WTUgEhE
TextureManager.h: http://pastebin.com/Ka17mbbg
TextureManager.cpp: http://pastebin.com/iZamup1m
Grass.cpp http://pastebin.com/sr3VADTP

And the exact errors:
http://pastebin.com/bDnmX7YD

Share this post


Link to post
Share on other sites
This isn't the proper way to handle global variables, you don't declare them in your header file.


GLuint Texture_Block_Grass;
GLuint Texture_Block_Dirt;
GLuint Texture_Block_TreeBark;
GLuint Texture_Block_GrassDirt;
GLuint Texture_Block_TreeCenter;
GLuint Texture_Block_Stone;
GLuint Texture_Block_Plank;

//Smooth Map Textures
GLuint Texture_Grass;
GLuint Texture_Street;
GLuint Texture_StreetCenter;
GLuint Texture_StreetCracked;
GLuint Texture_Dirt;
GLuint Texture_Mud;
GLuint Texture_Sand;
GLuint Texture_Stone;
GLuint Texture_SideWalk;
GLuint Texture_SideWalkCracked;
GLuint Texture_Concrete;



You want to have it like this:
TextureManager.h

extern GLuint Texture_Block_Grass;


TextureManager.cpp

GLuint Texture_Block_Grass



The problem is that every time a file reads TextureManager.h it's creating a new global variable of that name, so the second file that includes it is having a conflict.

So you just want your header to declare it "extern", and then just declare it once in a .cpp file.

Share this post


Link to post
Share on other sites
Ok well i got rid of most of the linker errors but now I got some other ones.


1>------ Build started: Project: Test, Configuration: Release Win32 ------
1> Exectute.cpp
1> Grass.cpp
1> TextureManager.cpp
1>Grass.obj : error LNK2001: unresolved external symbol "unsigned int Texture_Block_Grass" (?Texture_Block_Grass@@3IA)
1>Grass.obj : error LNK2001: unresolved external symbol "unsigned int Texture_Block_GrassDirt" (?Texture_Block_GrassDirt@@3IA)
1>Grass.obj : error LNK2001: unresolved external symbol "unsigned int Texture_Block_Dirt" (?Texture_Block_Dirt@@3IA)
1>C:\Users\Owner\Documents\Visual Studio 2010\Projects\Test\Release\Test.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites

This topic is 2540 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this