Solved

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

Posted on 2001-06-19
11
978 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

832 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