Jump to content
  • Advertisement
Sign in to follow this  

Linker Error's With Texture Manager

This topic is 2827 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:

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:

extern GLuint Texture_Block_Grass;


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
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!