Re: Linker error - fooView.obj LNK2005: _IID_IProvideTaskPage already defined in fooDoc.obj

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 02/26/04


Date: Thu, 26 Feb 2004 05:27:51 -0500

It is clear that you are declaring the variable in both the view and the document.
However, it is impossible to guess as to how you got this symbol defined twice.

I suspect that the problem lies with the INITGUID definition. Go search for DEFINE_GUID in
basetyps.h and read the comments surrounding it..

My analysis consisted of:
        search all header files for the definition if IID_ITaskScheduler
        discover it is a DEFINE_GUID macro
        search for the definition of DEFINE_GUID
        read the comments

It is obvious from the macro definition and the comments that if you got the INITGUID
definition wrong, you will get multiple definitions.

A more elaborate diagnosis would have consisted of adding the /P (note the uppercase)
option manually to the command line and recompiling both the view and doc files (don't
compile anything else if you can help it; it will take forever and massive amounts of disk
space), then search the resulting .i files for declarations of the offending variable, and
see where it came from. This would have revealed the expansion of the macro gave two
declarations, one in the document and one in the view.

The MSDN article that indicates LNK2005 errors are from conflicts with single-threaded and
multithreaded libraries would refer to symbols in the single-threaded and multithreaded
libraries, and these symbols do not releate to the single-threaded or multithreaded
libraries, so the article is completely irrelevant. Unless someone in the header files is
trying real, real hard, iIt would not cause symbols that have nothing to do with the
libraries to become multiply-defined.

Look for simple solutions first. And the simple solution is that you declared it twice.
                                        joe

On Thu, 26 Feb 2004 01:46:10 -0800, "Al" <anonymous@discussions.microsoft.com> wrote:

>> Sounds like you have included a header file what declares an IID_ and CLSID_ variable in
>> the .h file, and the .h file is now included in two other files. Never declare variables
>> in header files.
>> joe
>
>Yes, that would produce that error. I don't think I do that though, I'll just double-check... Nope, the text "_IID_ITaskScheduler" (one of the definitions the linker complains about) doesn't appear anywhere in my project. "IID_ITaskScheduler" does appear in .cpp files in calls to CoCreateInstance() but its not in any header files and its not a declaration.
>
>IID_ITaskScheduler is declared as extern in MSTask.h but that shouldn't be a problem and its a Microsoft header file anyway. I don't think having it defined in 2 places is the direct cause.
>
>MSDN says that error LNK2005 is most commonly caused by accidentally linking to both the single and multi threaded libraries... The only likely setting I can find for this is in the [Code Generation] category of the [C/C++] tab of the [Project Settings] dialog where I have selected to use the [Debug Multithreaded DLL] runtime libraries. I can't see how I could be accidentally linking to both libraries. Is there another setting I should be looking at?
>
>Any further ideas?
>
>--- Al.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: Link errors
    ... C code *compiled for Windows CE*, not for the x86 emulator, right? ... Most well-designed C libraries will do the right thing and wrap their ... <declarations here> ... If the header files for this library don't have that, ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Linker error multiple definitions
    ... > I declared the functions in separate header files ... But your compiler isn't complaining about multiple *declarations*. ...
    (comp.lang.c)
  • Re: Ahead of "main"?
    ... The latter style is effectively required when you move to multi-file projects, and the standard practice is to put all of your function declarations in header files so that each source file can simply #include the appropriate header files and then use whatever functions are needed. ... Actually, you should not put *all* your function definitions in header files, since generally there are some which should be local to a given source file and declared static in that source file. ...
    (comp.lang.c)
  • Re: [patch 1/3] epoll cleanups - epoll include diet ...
    ... and it certainly needs to have those syscall's prototypes in scope. ... Ack about signal.h, I forgot about the pwait code:( ... So that the compiler can verify that our declarations of sys_epoll_foo ... include in .c the header files which provide the stuff ...
    (Linux-Kernel)
  • Re: [C] Libraries and headers
    ... > 1) Libraries are files containing one or more object files which include the ... > variables declarations, templates, constants and macros. ... I would only put global variables in header files if they were declared ... extern int MyGlobal; ...
    (alt.comp.lang.learn.c-cpp)