Solved

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

Posted on 2001-06-19
11
983 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

751 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