Linker Error's With Texture Manager

Started by
1 comment, last by TTT_Dutch 13 years, 3 months ago
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
Advertisement
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 TexturesGLuint 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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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 ==========

This topic is closed to new replies.

Advertisement