Solved

DllMain defined both in mfcs40.lib and MSVCRT.lib

Posted on 1997-04-11
3
576 Views
Last Modified: 2013-11-20
I have created a regular DLL that uses MFC as a shared
library. The DLL contains some dialogs, and is called
through an exported (non-MFC) class.
This works fine.
After exiting from MSDev and opening the project again, I
add one more source file to the project, or change a
#define. Everything compiles OK, but I get the link error:

mfcs40.lib(dllmodul.obj) : error LNK2005: _DllMain@12
already defined in MSVCRT.lib(dllmain.obj)

I tried replicating this behavior in a small project, but
the error didn't show up.
Is this an MSDev bug? Is there a workaround?
0
Comment
Question by:yonat
[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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
sapek earned 100 total points
ID: 1300975
I had exactly the same error a few days ago. I don't know the reason for this to happen but I have a workaround. Go to your project build setting link page, select Input category and add mfcs40.lib (mfcs40d.lib for debug build) *both* to "Object/Library modules:" and "Ignore libraries:" edit boxes. I believe it help by making linker to look at mfcs40.lib after MSVCRT.lib.

Hope this also work for you.

Adam
0
 
LVL 5

Author Comment

by:yonat
ID: 1300976
Thanks a million!
0
 
LVL 5

Author Comment

by:yonat
ID: 1300977
I have found the reason!

This error occurs when one of the cpp files in the project does not include any MFC header and uses new/delete. MFC code needs its own new/delete ops and they conflict with the ones that non-MFC C++ code links to.

The solution: put #include <afx.h> (or #include "stdafx.h") in all non-MFC C++ sources.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 102
pre4 challenge 19 110
unix example issues 18 106
Work with App store 7 92
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

756 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