Jump to content
  • Advertisement
Sign in to follow this  
JohnnyCode

linker error

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

hello, I have this problem. I declare a class in a header like this #ifndef HE_TEXTURE_MANAGER #define HE_TEXTURE_MANAGER class CTextureManager { ... }; #endif my project builds fine, but when I try to create an instance of this class in the header this way: #ifndef HE_TEXTURE_MANAGER #define HE_TEXTURE_MANAGER class CTextureManager { ... } sTextureManager; #endif I get a linker eror in all .obj files that include this header, the error is : Linking... 1>Texture.obj : error LNK2005: "class CTextureManager sTextureManager" (?sTextureManager@@3VCTextureManager@@A) already defined in Mesh.obj 1>TextureManager.obj : error LNK2005: "class CTextureManager sTextureManager" (?sTextureManager@@3VCTextureManager@@A) already defined in Mesh.obj I include the header in mesh.cpp, texture.cpp and texturemanager.cpp. Why can't I have instance of this class in header it is declared in?

Share this post


Link to post
Share on other sites
Advertisement
Global variables can't be defined in headers. You can declare the global in the header as extern and then define it in a source file.

// in the header
extern CTextureManager sTextureManager;

// in one source file
CTextureManager sTextureManager;


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!