Link to home
Start Free TrialLog in
Avatar of cternoey
cternoey

asked on

error LNK2005: (already defined)

When I compile my program, I see linking errors like this...
  error LNK2005: _IID_IBoundObjectSite already defined in nafxcwd.lib(occsite.obj)

The problem seems related to my using the Platform SDK header files.
Because I am using some functions defined in the wininet.h update,
I have added "C:\Program Files\Microsoft Platform SDK\Include"
under Tools->Options->Directories

When I place the sdk include directory before all others,
I get the redefinition linking errors.

When I place the sdk include directory after all others,
I get compiler errors like this...
  error C2065: 'NIF_INFO' : undeclared identifier
  error C2039: 'szInfo' : is not a member of '_NOTIFYICONDATAA'

So some data-structs and constants are not defined if I list the SDK headers last,
but I will get redefinition link errors, if I put the sdk headers first.
What can I do?

One last clue,...
The problem seems to go away when I put the sdk headers first
and link 'dynamically' not 'staticly' to mfc.

Please help.
Any suggestions are much appreciated.
-c
Avatar of jhance
jhance

Linker Tools Error LNK2005
symbol already defined in object

The given symbol, displayed in its decorated form, was multiply defined.

Tips

One of the following may be a cause:

The most common cause of this error is accidentally linking with both the single-threaded and multithreaded libraries. Ensure that the application project file includes only the appropriate libraries and that any third-party libraries have appropriately created single-threaded or multithreaded versions.


The given symbol was a packaged function (created by compiling with /Gy) and was included in more than one file but was changed between compilations. Recompile all files that include the symbol.


The given symbol was defined differently in two member objects in different libraries, and both member objects were used.


An absolute was defined twice, with a different value in each definition.
Avatar of cternoey

ASKER

I have already read the help file, with little benefit.
Thanks anyway,
-c
Avatar of DanRollins
I suggest using #include "surgically":  Don't change the order of the directory list or add directories to it.  Instead, include specific files into the .cpp files that need them:

#include "stdafx.h"
#include "MyProg.h"
#include "wininet.h" // or "c:\dev\inc\winindet.h"

Does that make any difference?  If not, try this:  
1) Put the preprocessor directories back to the original settings
2) Compile (you should see the errors like "struct xxx is undefined" that you mentioned).
3) now show us the list of #defines that you are using in the file that fails to compile.

-- Dan
these are great suggestions.
i'll try them right away.
Thanks!
-c
The first tact did not work too well.
The problem with hardcoded includes like this...
#include "C:\Program Files\Microsoft Platform SDK\Include\wininet.h"
seems to be that those includes (e.g. wininet.h) may have symbols that are defined
elsewhere (e.g. in somethingelse.h), but only the old version
of somethingelse.h will be found considering the directory rules.
I saw an explosion of complaints that wininet.h contained
the undefined sybol 'DWORD_PTR'

Detailing the error messages when
C:\Program Files\Microsoft Platform SDK\Include\
is in ther diectories list below other directories,
I have these 8 errors...
error C2065: 'NIF_INFO' : undeclared identifier
error C2039: 'szInfo' : is not a member of '_NOTIFYICONDATAA'
error C2039: 'szInfoTitle' : is not a member of '_NOTIFYICONDATAA'
error C2039: 'uTimeout' : is not a member of '_NOTIFYICONDATAA'
error C2039: 'dwInfoFlags' : is not a member of '_NOTIFYICONDATAA'
error C2065: 'NIIF_INFO' : undeclared identifier CsIeVersionFinder.cpp
error C2065: 'INTERNET_CONNECTION_OFFLINE' : undeclared identifier
error C2065: 'InternetGetConnectedState' : undeclared identifier
(increasing points)
I'll check into this further later, but I have in the past done kludgy stuff like..

#define NIF_INFO  <the value I found in the right header>

....to get things off the ground.

Also, I see in MSDN that:

#define _WIN32_IE 0x0500

needs to be in you project defines or in stdafx.h (or otherwise early on in the header chain).

-- Dan
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My first born shall be named BekiM.