Thread: error LNK2005: _DllMain@12 already defined in SPLibrSync.obj

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    error LNK2005: _DllMain@12 already defined in SPLibrSync.obj

    I have a C code files. I have to create a Win32 DLL using the .c and .h files. Now when i included this file one by one. Now i am getting the error as "error LNK2005: _DllMain@12 already defined in SPLibrSync.obj". Will anyone please come ahead and solve this problem. Please do the needful.

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    It sounds like you have acidently included main twice in the project.
    Double Helix STL

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Hello Sir,

    I have gone through my code and no where i have double main statement.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    What does the function definition look like?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Do you have code inside .h files?
    Do you #include source files inside other source files?

    Both of these poor practices will lead to multiple definitions at the linker, even if they only appear once in actual source code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Quote Originally Posted by Laserve
    What does the function definition look like?
    the function defination looks like :

    Code:
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
        switch (ul_reason_for_call)
    	{
    		case DLL_PROCESS_ATTACH:
    		case DLL_THREAD_ATTACH:
    		case DLL_THREAD_DETACH:
    		case DLL_PROCESS_DETACH:
    			break;
        }
        return TRUE;
    }

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    And how many times do you include this header file?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    go to this source file, SPLibrSync. You have DllMain() defined there.

    Now, it can be either because it's actually coded in that file, because you are including the cpp file that defines it (never include cpp files), or you are including an header (.hpp or .h) file that has it defined (never define functions inside header files unless they are inline functions).

    Search for those three situations starting with SPLibrSync.cpp
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking problems in Visual Studio
    By h3ro in forum C++ Programming
    Replies: 5
    Last Post: 03-04-2008, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Variables already defined while linking.
    By xconspirisist in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2005, 05:20 AM
  4. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM
  5. Header files
    By borland_man in forum C++ Programming
    Replies: 14
    Last Post: 02-22-2002, 04:30 AM