Solved

std .dll problems: warning LNK4006: _DllMain@12 already defined

Posted on 2001-06-19
11
947 Views
Last Modified: 2013-12-14
I'm trying to develop a simple standard .dll in C++ to be called by VB.  I've done this on many occasions but this is the first time that I'm using MFC support.  When I compile, I get the following error (I set the verbose flag):

Deleting intermediate files and output files for project 'KerrysTracker - Win32 Debug'.
--------------------Configuration: KerrysTracker - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
KerrysTracker.cpp
Linking...
Searching Libraries
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfc42d.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfcs42d.lib:
mfcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in KerrysTracker.obj
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\msvcrtd.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\kernel32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\user32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\gdi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comdlg32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\winspool.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\advapi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\shell32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comctl32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\uuid.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\OLDNAMES.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\olepro32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\ole32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\oleaut32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfc42d.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfcs42d.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\msvcrtd.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\kernel32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\user32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\gdi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comdlg32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\winspool.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\advapi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\shell32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comctl32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\uuid.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\OLDNAMES.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\olepro32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\ole32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\oleaut32.lib:
Done Searching Libraries
mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in KerrysTracker.obj; second definition ignored
   Creating library Debug/KerrysTracker.lib and object Debug/KerrysTracker.exp
Searching Libraries
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfc42d.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfcs42d.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\msvcrtd.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\kernel32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\user32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\gdi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comdlg32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\winspool.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\advapi32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\shell32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\comctl32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\uuid.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\OLDNAMES.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\olepro32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\ole32.lib:
    Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\oleaut32.lib:
Done Searching Libraries
Debug/KerrysTracker.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

KerrysTracker.dll - 2 error(s), 1 warning(s)


The MSDN says:

There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and correct it.

I'm not sure how to do either option.

Please walk me through this one so that I can produce the .dll.

Thanks in advance!
0
Comment
Question by:khampton
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 4

Expert Comment

by:IainHere
ID: 6209657
It _might_ be because you haven't got #include "stdafx.h" first in your list of includes.  It's worth a shot at least :)
0
 

Accepted Solution

by:
janiv earned 100 total points
ID: 6209693
Remove the _USRDLL option from :
Project -> Setting -> c/c++ tab -> preprocessor definition line .
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6209730
Just out of interest, why would _USRDLL fix it?  I thought it was just for statically linking to the MFC?
0
 

Expert Comment

by:janiv
ID: 6209746
Because it has both _USRDLL and _WINDLL !
0
 

Expert Comment

by:mkprasad
ID: 6211047
Try setting
    Project->Settings->C/C++ -> (category:)CodeGeneration  ->runtime library
    to ==> (Debug)multithreaded DLL.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:khampton
ID: 6220030
to:  janiv
from: khampton

Your solution worked! I will award you the points but I would like just a little more dialog on this subject if you please...

How did you learn about this technique? (I didn't see anything concerning this in MSDN).

I've been a VB programmer for years and just started to use VC++ about 6 months ago. All of the undocumented stuff (like this) is driving me crazy.  Besides MSDN and this Experts Exchange service, how do you get information on tricky problems?  (Please don't tell me to call Redmon).

Anyway, a little more feedback is very welcome.  Thanks again.




Q105286
0
 

Expert Comment

by:mkprasad
ID: 6221115
Hi Redmon,

The following content is from MSDN:

/***********************************/
Linker Tools Error LNK2005
symbol already defined in object
 ...

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.
 ...
/*******************************/

And this is one of the problems i faced when i was new to VC environment, with my seniors help i could solve it.
But it is documented in MSDN atleast the version i am using now.

Anyway, experience will teach you many things.

GoodLuck,
PrasadMK
0
 

Expert Comment

by:mkprasad
ID: 6221118
Sorry,
The first line in the above comment is misspelt,
From Redmond,
0
 
LVL 1

Author Comment

by:khampton
ID: 6221622
Actually, it was removing the _USRDLL that fixed the problem - not the multithreading fix.
0
 

Expert Comment

by:janiv
ID: 6222371
khampton,
I'm sorry, but years of experiance brought me to know it.
Try to read section TN011 in the msdn (just type TN011 in the index field of MSDN).
0
 

Expert Comment

by:mkprasad
ID: 6223401
Sorry khampton,
 i misunderstood the comment :-)
thank u janiv for the new useful info.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 28
Move constructor only called if marked noexcept? 6 98
Delphi : could not find program, '...exe' 2 147
Dialogbox API leak? 18 81
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now