Thread: LNK2005 Linker Error

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    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.
    Last edited by Jonnster; 03-29-2011 at 08:34 AM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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.
    Last edited by CommonTater; 03-29-2011 at 08:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM