Archived

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

Kaezin

Stupid newbie errors

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites