-
I am using VC 6 and have an application which links in several static libraries. Everything had been working fine but now when I build the main exe I get the following error:
Code:
libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in lib_one.lib(libone.obj)
I can't see anything that has changed that would cause this. Does anyone have any ideas please?
I should have also said that the problem is only in a release build.
-
It's telling you that you have the same function defined in two different libraries...
There are a couple of things that can cause this...
1) A duplicate definition
2) headers included more than once
Usually it's #2... Which means you need to use include guards (good practice, on all headers).
Code:
// my header.h
#ifndef MYHEADER_H
#define MYHEADER_H
// body of myheader...
#endif // MYHEADER_H
The idea is that the first time through, the #define is not set and the header is included. On subsequent inclusions, since the define exists, the header is not included again and does not cause the duplicate definition error.