VC 7.0 Linker Error LNK2005, LNK4006, LNK1169 _DllMain@12 already defined in MyDll.obj 
Author Message
 VC 7.0 Linker Error LNK2005, LNK4006, LNK1169 _DllMain@12 already defined in MyDll.obj

Hi NG:

I am porting a .DLL which uses MFC from VC 5.0 to 7.0.  No problems
creating the project, specifying that it does use MFC, etc.  However,
I get the following errors when linking it:

Linking...

in WdRegistryManager.obj

defined in WdRegistryManager.obj; second definition ignored
   Creating library \bin\debug/WdRegistryManager.lib and object
\bin\debug/WdRegistryManager.exp
\bin\debug/WdRegistryManager.dll : fatal error LNK1169: one or more
multiply defined symbols found

Build log was saved at
"file://k:\Lib\Dll\Wd\WdRegistryManager\Debug\BuildLog.htm"
WdRegistryManager - 2 error(s), 1 warning(s)

Following some earler advice for VC6, I was able to come up with a
workaround, manually specifying /FORCE on the command line for the
linker.  This generates some {*filter*} sounding warnings, but the .DLL
does successfully link.

Am I improperly trying to use MFC?  Is there a better way to use my
DllMain() and not the one in mfcs70d.lib?  I tried to /NOD:mfcs70.lib
and add it to the additional libraries, as in VC 5.0 and VC6.0, but
that does not appear to be possible with 7.0.

Any advice appreciated.

Thanks,
J. R.



Sun, 03 Apr 2005 00:37:33 GMT  
 VC 7.0 Linker Error LNK2005, LNK4006, LNK1169 _DllMain@12 already defined in MyDll.obj
Further news and information on this.  To reproduce the problem from
scratch, I:

1)  Created a new blank solution, C:\TestSolution
2)  Added a new Visual C++ Project/Win32 Project to the solution
called Dazzle (C:\TestSolution\Dazzle).
3)  In the Applications Tab of the Win32 Application Wizard that pops
up, I selected DLL Radio Button only.  Pressed Finish.
4)  Selected the Dazzle project in Solution Explorer, right click,
Project Properties.
5)  In the Under Configuration Properties/General, I changed the Use
of MFC Drop Down List to Use MFC in a shared DLL (Just concerned with
Debug configuration for now).  LEFT USE OF ATL OFF.  Pressed Ok.
6)  Changed contents of StdAfx.h (below #pragma once) from:
--------------------------------
#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows
headers
// Windows Header Files:
#include <windows.h>

// TODO: reference additional headers your program requires here
--------------------------------
to:

--------------------------------
#define VC_EXTRALEAN            // Exclude rarely-used stuff from
Windows headers
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions

// TODO: reference additional headers your program requires here
--------------------------------

7)  Press build.  Results:

Compiling...
stdafx.cpp
Compiling...
Dazzle.cpp
Linking...

in Dazzle.obj
Debug/Dazzle.dll : fatal error LNK1169: one or more multiply defined
symbols found

8)  If I manually add /FORCE to the link command line, I get:

Compiling...
stdafx.cpp
Compiling...
Dazzle.cpp
Linking...
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/FORCE'
specification

defined in Dazzle.obj; second definition ignored
Debug/Dazzle.dll : warning LNK4088: image being generated due to
/FORCE option; image may not run

Build log was saved at
"file://c:\TestSolution\Dazzle\Debug\BuildLog.htm"
Dazzle - 0 error(s), 3 warning(s)

Any thoughts on why this doesn't work or what I have done wrong here
are appreciated.

Thanks,
J. R.



Sun, 03 Apr 2005 22:27:32 GMT  
 VC 7.0 Linker Error LNK2005, LNK4006, LNK1169 _DllMain@12 already defined in MyDll.obj

Quote:
>Further news and information on this.  To reproduce the problem from
>scratch, I:

Start from a new MFC DLL project instead.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Mon, 04 Apr 2005 19:07:23 GMT  
 VC 7.0 Linker Error LNK2005, LNK4006, LNK1169 _DllMain@12 already defined in MyDll.obj
Yes, that is what I did.  I started from an MFC Extension DLL, more
precisely, and then re-integrated the code I am porting into the DllMain it
produced.  The plain old MFC DLL gives you no DllMain.  You have to code
into the MFC extensions, which can be painful if you're porting from MSVC
5.0 or Visual Studio 6.0 to 7.0 .NET.

In that effort and in wanting to fully understand the problem, I did
discover why what I did did not work...  The C++ /D options (aka
Preprocessor definitions) include _USRDLL instead of _AFXEXT.

So, I might have created an empty Win32 project, added my files to it, and
then copied and used the StdAfx and Preprocessor Definitions for my
extension DLL (from a test stub project generated from the Wizards), which
is a valuable tip if you are trying to port from an older version of Visual
Studio to 7.0.

On a side note, old .DSP and .DSW files may convert to the new .VCPROJ stuff
and compile, link, and work.  However, my experience is that this does not
work nearly so well as adding the existing files to the project via 7.0.
Studio.NET does a good job of keeping track of sources, includes, generated
files, etc., but it doesn't pick up on that when it converts an old project
to a new.  (Add your headers, .IDL files, .RC, or whatever, it knows how to
handle it and still provides for custom build stuff (MIDL being no longer
"Custom" though).

While I am at it, I am revamping the build process and include scheme
(har-har) to conform to the StdAfx way of doing business.  It's making it so
much more clear to me what the actual dependencies between all the pieces
are...  and it compiles a lot faster, too.  *G*  So I guess there is a
silver lining to every cloud...

I hope this info helps somebody, somewhere, someday.

J. R.



Tue, 05 Apr 2005 08:25:17 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. error LNK2005: _DllMain@12 already defined

2. DllMain@12 already defined in MSVCRT

3. _DllMain@12 already defined

4. _DllMain@12 already defined

5. Linker error: DllMain already defined

6. LNK2005 DLLMain, pRawDLLMain already defined

7. What defines _DllMain@12

8. DllMain already defined error

9. ERROR LNK2005: _Lockit already defined

10. error LNK2005: - already defined problem

11. Link errors in writing custom dll... "_DllMain@12 already defined "

12. linker error: operator delete already defined...

 

 
Powered by phpBB® Forum Software