Archived

This topic is now archived and is closed to further replies.

link errors!

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

i know this has been asked a thousand times but i tried to read a bunch of posts in the search and none of it made sense to me. i finally decided to go and split up into multiple headers and junk but i keep getting... window.obj : error LNK2005: "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A) already defined in main.obj and.. graphics.obj : error LNK2001: unresolved external symbol "float (* spriteColors)[3]" (?spriteColors@@3PAY02MA) which the 2nd i have no idea what it even means. i have no idea how to get around these. if you need more info please ask. -plasmicsoup Gilgamesh Games

Share this post


Link to post
Share on other sites
While you''re still using global variables (a habit you''ll eventually break from), you have to treat them specially when using multiple files.

Above all, use inclusion guards. This applies even when you have no globals. At the top of each header file, place something like this
#ifndef HEADER_FILE_NAME_H
#define HEADER_FILE_NAME_H

(where HEADER_FILE_NAME_H would be replaced with GRAPHICS_MODULE_H e.g. if the filename was graphicsmodule.h). Then at the end of the file add an
#endif

Now, onto the unresolved/redefined stuff. For each variable:

First, declare it as an external. You do that by placing this in every header file that uses the variable (example):
extern HWND hWnd;

Then, in one and only one source (.cpp) file, place the actual declaration:
HWND hWnd;
(You''d probably put that at the top of your "main" file)

As for the second, I''d need to see the code. Sounds like it might be fixed by following the above steps though.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites
What''s wrong with globals? I use globals for my class like "COpenGL" that handles an OpenGL window. It''s quite convenient. I''d rather not use a singleton - it''s too much hassle.

Share this post


Link to post
Share on other sites
Ok, problems. I have this fonttexid variable, and its extern int fonttexid in graphics.h, and defined in graphics.cpp, its value is altered in main.cpp (which includes graphics.h) but its value does not show up in graphics.cpp as what it was defined to in main.cpp. Uh... *scratches head*...

-plasmicsoup
Gilgamesh Games

Share this post


Link to post
Share on other sites
Haha ah man that sucks. Im getting just totally messed up results...

It turns out, all of my variables must be getting screwed up or something. All my texture coords are all messed up and all the graphics are garbled.

http://fragmachine.com/gilgameshgames/0.bmp <- messed up
http://fragmachine.com/gilgameshgames/g2-1.jpg <- how it should look

-plasmicsoup
Gilgamesh Games

Share this post


Link to post
Share on other sites
quote:
Original post by Tron3k
What''s wrong with globals? I use globals for my class like "COpenGL" that handles an OpenGL window. It''s quite convenient. I''d rather not use a singleton - it''s too much hassle.


Neither solution is ideal. To be totally OOP, you''d need to create an overarching abstraction layer like C[Engine/Game/System/Whate''er] which manages your renderer, even if there''s currently only one of them.

Globals are discouraged because they can be modified anywhere by anything, which leads to situations like the one PlasmicSoup is in now, and generally create unstructured, shoddy, unmaintainable, and non-modular code.

Plasmic: That does indeed look garbled... Can you supply evidence that: the variable has one value, a certain block of code which acts on it is then called, and, that the resulting value of the variable has in fact not changed? This is certainly your error; I just can''t tell anything without seeing any code.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites