Linker Errors..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 379
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Linker Errors..

 
0
  #1
Oct 25th, 2009
I am trying to make a 3D Engine using OpenGL, I've got all the model loading, 3D nodes, all that stuff done, but I get linker errors when I try to compile, it.. these are the errors:

------ Build started: Project: TheAlienEngine, Configuration: Debug Win32 ------
Compiling...
main.cpp
core.cpp
ae_3d.cpp
Generating Code...
c:\documents and settings\tom\my documents\visual studio 2008\projects\thealienengine\thealienengine\ae_3d.cpp(33) : warning C4700: uninitialized local variable 'model' used
c:\documents and settings\tom\my documents\visual studio 2008\projects\thealienengine\thealienengine\ae_3d.cpp(49) : warning C4700: uninitialized local variable 'node' used
Linking...
core.obj : error LNK2005: "struct options_t somecrazyoptions" (?somecrazyoptions@@3Uoptions_t@@A) already defined in main.obj
core.obj : error LNK2005: "struct node_t * _nodes" (?_nodes@@3PAUnode_t@@A) already defined in main.obj
ae_3d.obj : error LNK2005: "struct node_t * _nodes" (?_nodes@@3PAUnode_t@@A) already defined in main.obj
C:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\TheAlienEngine\Debug\TheAlienEngine.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\TheAlienEngine\TheAlienEngine\Debug\BuildLog.htm"
TheAlienEngine - 4 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have used include guards in all the header files and I have looked through the pre-processed file and I still couldn't find where those things are defined twice.. I've attached the code in a .zip file if you want to see.
Last edited by tomtetlaw; Oct 25th, 2009 at 7:34 am.
Attached Files
File Type: zip TheAlienEngine_Code.zip (1.02 MB, 3 views)
...
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,398
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 245
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #2
Oct 25th, 2009
Don't put data definitions in header files. Header guards will only ensure that only one copy exists in each source file in which it is included, but as you see you will get linker errors for multiple definitions. Put data and function definitions in source files.

Move the data definition to a single source file. If you want to allow access to this global data via the header file, extern it in the header.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC