Archived

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

Zeke

Already defined linker error help

Recommended Posts

Ive been trying to learn com for a while now and have a com object and a client that uses that object. Ive hit a hurdle however whilst adding a new dialog box to my client (which is a dialog based mfc app). The problem lies with the guid''s of the interfaces each interface is declared using DEFINE_GUID in its own header file (e.g. IID_IInterface1.h, IID_IInterface2.h etc). Both dialogs (the main app and the added dialog) require these guids so I need to #include them in each source file. However if i include IID_IInterface1.h in Dialog1.cpp and then again in dialog2.cpp i get a stream of linker errors specifying "Dialog1.obj : error LNK2005: _IID_IInterface1 already defined in Dialog2.obj" Which i think is fair enough seen as im including the file twice and therefore declaring the guid''s twice. So to solve this problem i decide to put all the #includes for these interface guids into my stdafx.h and therefore will only be declaring them once. Much to my surprise and annoyance i get the same stream of errors. The most peculiar thing with this is i coded and built and tested both the com server and client on my work computer and it works fine with all the includes in the stdafx file. Both computers are running visual studio allbeit my work comp probably has a more up to date version with service packs and the like-my home version is 6.0 but without any service packs installed. Does anyone have any idea of why this is happening or how to fix it or just any information at all? Anything would be helpful because im stuck at a dead end with nothing left to try. Thanks for any help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
did you use #ifdef or #ifndef? it looks like what is happening is the header file is being included more than once. So:

#ifndef
#define THIS_HEADER_FILE.H
// all code
#endif

if that''s not your problem, I have no idea.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I posted and while I was waiting I read the rest of your post...
If you only included everything once, as you said, then "I don''t know"

Share this post


Link to post
Share on other sites
Apparently in the msdn it says to use DEFINE_GUID outside of any
#ifndef __NAME_
things but i tried anyway and it gave the same errors. I just dont understand linker errors enough to know what is going or how to fix it.

Thanks for the reply though

Share this post


Link to post
Share on other sites