Advertisement

Stupid newbie errors

Started by July 28, 2002 04:11 PM
3 comments, last by Kaezin 22 years, 1 month ago
Alright my code compiles just fine, but I get these errors when it tries to link: Deleting intermediate files and output files for project ''OpenGL - Win32 Debug''. --------------------Configuration: OpenGL - Win32 Debug-------------------- Compiling... main.cpp Graphics.cpp Linking... Graphics.obj : error LNK2005: "float walkbiasangle" (?walkbiasangle@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "bool active" (?active@@3_NA) already defined in main.obj Graphics.obj : error LNK2005: "unsigned int * texture" (?texture@@3PAIA) already defined in main.obj Graphics.obj : error LNK2005: "float walkbias" (?walkbias@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in main.obj Graphics.obj : error LNK2005: "float lookupdown" (?lookupdown@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "bool fp" (?fp@@3_NA) already defined in main.obj Graphics.obj : error LNK2005: "bool bp" (?bp@@3_NA) already defined in main.obj Graphics.obj : error LNK2005: "float heading" (?heading@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "unsigned int filter" (?filter@@3IA) already defined in main.obj Graphics.obj : error LNK2005: "float zpos" (?zpos@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "float yrot" (?yrot@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "bool blend" (?blend@@3_NA) already defined in main.obj Graphics.obj : error LNK2005: "bool * keys" (?keys@@3PA_NA) already defined in main.obj Graphics.obj : error LNK2005: "float xpos" (?xpos@@3MA) already defined in main.obj Graphics.obj : error LNK2005: "float z" (?z@@3MA) already defined in main.obj Debug/OpenGL.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe. OpenGL.exe - 17 error(s), 0 warning(s) I know it''s because I #included main in two files, but how do I stop these errors? I tried doing something like

#ifndef MAIN
#define MAIN
...
//Do everything I need to do
...
#endif 
But that didn''t work. Can anyone help out a poor newbie who is trying to use OpenGL?
Half the people you know are below average.Trogdor the Burninator
Never include source (.c, .cpp) files. Only include headers. The header should preferably begin with a #ifndef/#define/#endif structure, as you indicated, but the source files should not be included -- merely compiled and linked in the same project.
Advertisement
I didn't include the .cpp files, only main.h
And I tried using the #ifndef/#define/#endif but it didn't work =(

*Edit* I got around the problem for the time being, but I still need to know how to do this for later on

[edited by - Kaezin on July 28, 2002 5:37:38 PM]
Half the people you know are below average.Trogdor the Burninator
Ah, I see -- I should have seen it at once. Perhaps you have defined variables in the header files rather than the source files? This should never be done -- declare the variables as extern in the header and define it in a source file somewhere (you have to re-declare it). Someone wrote an excellent article on just this sort of problems on GameDev not too many months ago ... try searching for it.
What kind of moron wouldn''t have declared them extern first? How dumb do you think I am?
*Looks over his code*
I... umm...
*A muttered, "Thank you", is heard*
Half the people you know are below average.Trogdor the Burninator

This topic is closed to new replies.

Advertisement