Solved

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

Posted on 2001-06-19
11
937 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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