[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2001-06-19
11
Medium Priority
?
1,004 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 400 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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: …
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…
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.

590 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