Forcing a Link due to LNK2005 
Author Message
 Forcing a Link due to LNK2005



Quote:
>  Hi,

> When is it ok to use the /FORCE option to force a link?  I have been
getting
> a LNK2005 which claims that some symbols were multiply defined.  I go
ahead
> and use the /FORCE option and everything works.

> Additional details:

[snipped]
> The above configuration gives me LNK2005 telling me that IID's CLSID's
etc.
> are defined more than once.

> However,  if I move the implementation for my methods from the cpp file
to
> the .h file (I know bad programming practice but STL does it!) everything
> compiles when I take masterimp.cpp out of my project.

Hi,

it seems that you are including initguid.h more than once. My docs say that
initguid.h must be included just in one source file and not included in the
rest of sources.

Hope this helps.




Sun, 12 Mar 2000 03:00:00 GMT  
 Forcing a Link due to LNK2005

 Hi,

When is it ok to use the /FORCE option to force a link?  I have been getting
a LNK2005 which claims that some symbols were multiply defined.  I go ahead
and use the /FORCE option and everything works.

Additional details:

The setup of my project is as follows:

ATL wizard generated app
The main file master.cpp includes the following

#include "stdafx.h"
#include "resource.h"
#include "initguid.h"
#include "Master.h"

#include "Master_i.c"
#include "MasterImp.h"    //from my COM object

The header file which contains the definition for my object is called
MasterImp.cpp and include's the following

#include "resource.h"       // main symbols
#include "mstraccess.h"    //from another COM server.  Needed because I
implement a Sink.
#include "mstraccess_i.c"

#include <stdio.h>

MasterImp.cpp has the method definitions and includes the following
#include "stdafx.h"
#include "Master.h"
#include "MasterImp.h"

The above configuration gives me LNK2005 telling me that IID's CLSID's etc.
are defined more than once.

However,  if I move the implementation for my methods from the cpp file to
the .h file (I know bad programming practice but STL does it!) everything
compiles when I take masterimp.cpp out of my project.

Am I including improperly?  I have left things pretty much the way the ATL
wizard gave them to me except for the mstraccess.h and mstraccess_i.c files.
It seems like I should be able to include mstraccess.h and _i.c without
getting this error.

I guess what I am wondering is if I force it will it cause negative
repercussions down the road?



Sun, 12 Mar 2000 03:00:00 GMT  
 Forcing a Link due to LNK2005


Quote:

>However,  if I move the implementation for my methods from the cpp file to
>the .h file (I know bad programming practice but STL does it!)

Just so you know, STL does this because it MUST, since it's implementing
templates, and because of the way the Microsoft compiler builds template
classes, the entire implementation must be available to any module that
uses the templates -- so the implementation *HAS* to be in the .H file.

  Katy



Mon, 13 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linker Warnings... (ignoring /INCREMENTAL due to /FORCE specification)

2. PRB: LNK2005 Errors When Link C Run-Time Libraries Are Linked Before MFC Libraries (Q148652)

3. Link problems due to library's strange behaviour

4. Link Errors : error LNK2005 and LNK2004

5. Please Help! - Link Error LNK2005

6. help- Link error LNK2005

7. Link Err LNK2005

8. LNK2005 Link errors when doing Release Build??

9. link problem, error LNK2005 using CSocket

10. Please Help! - Link Error LNK2005

11. LNK2005 Link errors when doing Release Build??

12. Link error (LNK2005) - Any suggestions

 

 
Powered by phpBB® Forum Software