Re: error LNK2005 by Scott
Scott
Tue Jun 22 18:07:37 CDT 2004
David Gerstman wrote:
>
> "Jeff Partch" wrote:
>
>
>>"David Gerstman" <dhgerstman@NOSPAM.hotmail.com> wrote in message
>>news:016353E4-14A6-4EA4-8754-DA1F20CA1BB8@microsoft.com...
>>
>>>I am getting the LNK2005 for mulitple definitions of all my subroutines.
>>>Here's my structure:
>>>cc_main.cpp - contains the code fore main()
>>>cc_subs.cpp - contains the various routines called by main()
>>>cc_lib.h - the definitions for the subs.
>>>
>>>in cc_main I have the #include "cc_subs.cpp" directive
>>>in cc_subs I have the #include "cc_lib.h" directive
>>>
>>>at the top of both cc_subs.cpp and cc_lib.h I have the #ifndef statements
>>
>>that were supposed to avoid the multiple linking.
>>
>>Try commenting out (or removing) the #include "cc_subs.cpp" in
>>'cc_main.cpp'.
>>--
>>Jeff Partch [VC++ MVP]
>>
>>
>
> I did and I got a couple of undefined identifiers; for the two subs that I call in
> main().
>
>
main should #include the cc_lib.h file. It should not #include the cpp.
The #ifndef statements that guard against multiple includes only protect
against including the same file more than once within a compilation
unit: I.e. recursively. You seem to have two compilation units, and
seem to have started out by compiling the subs twice: once when
cc_subs.cpp is compiled, and - because you included the cpp - again when
cc_main.cpp is compiled.
--
Scott McPhillips [VC++ MVP]