Archived

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

Link Error with VC++ LNK2005

This topic is 5700 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''m getting the following error when Linking... Linking... initLights.obj : error LNK2005: "float * lightPositionB" (?lightPositionB@@3PAMA) already defined in main.obj initLights.obj : error LNK2005: "float * lightPositionG" (?lightPositionG@@3PAMA) already defined in main.obj initLights.obj : error LNK2005: "float * lightPositionR" (? Debug/Lighting.exe : fatal error LNK1120: 9 unresolved externals Error executing link.exe. along with 15 more saying the same thing for different variables I have the previous variables "DEFINED" in a header file. When it says it''s already defined in main.obj I get lost. I didnt'' define anything there. All I have are function calls, and those functions, in a seperate .cpp file use those variables. I''ve included all the .h files accordingly, by I can''t figure out this linker error. Help anyone? Keep On Smiling

Share this post


Link to post
Share on other sites
Your .h files aren''t compiled; .cpp files are. Therefore, if your variable definitions are in .h file which is included in two .cpp files, those definitions are compiled twice. Use extern in .h files and define variables in .cpp files. There''s a good article here on GameDev regarding this issue.

Share this post


Link to post
Share on other sites
Yeah... declare variables in headers, define them in a single source file. As IndirectX says, there''s an article here on GameDev.net which I wrote on this and related topics: it''s the last link in my signature.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites