Solved

error:  Please use the /MD switch for _AFXDLL builds

Posted on 2008-10-28
10
5,107 Views
Last Modified: 2013-11-20
Hi Experts,

How can I fix this ?  I'm using Visual Studio 2008 C++ with MFC.....

Thank you!
Mike
0
Comment
Question by:thready
  • 4
  • 4
  • 2
10 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22824888
If your project is an MFC application (.exe) goto the project properties - C/C++ page - Code generation and choose 'Multi-Threaded DLL' for Release configuaration and 'Multi-Threaded-Debug-Dll' for Debug configuration.

That should solve the issue.

0
 
LVL 14

Expert Comment

by:wayside
ID: 22824902
Project->Properties, expand "Configuration Properties" on the left, expand "C/C++", select "Code Generation".

On the right side, click the box next to  "Runtime Library" and select "Multithreaded DLL (/MD)" from the combo pulldown.
0
 
LVL 1

Author Comment

by:thready
ID: 22824976

When I change to this option - it give me this error:

Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

Any ideas?
Thanks,
Mike
0
 
LVL 14

Expert Comment

by:wayside
ID: 22825093
What setting to you have in Project->Properties->Configuration Properties->General in the "Use of MFC" box?

It should say "Use MFC in a Shared DLL".
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22825105
>>>> requires MFC shared dll version
It looks as if your MFC app wanted to use static MFC libraries (that is one of the options you have when you create the app using the wizard). Unfortunately that setting conflicts with some header errors.

Try to define the _AFXDLL in the preprocessor macros (simply add the _AFXDLL to the already defined list separated by ;) at C/C++  - preprocessor
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:wayside
ID: 22825216
> Try to define the _AFXDLL in the preprocessor macros

Setting the "Use of MFC" setting to "Use MFC in a Shared DLL" does this for you.
0
 
LVL 1

Author Comment

by:thready
ID: 22825304

Hmmmm..  I think I might be getting somewhere....  I'm now getting a whole bunch of these errors  (having to do with msvcprtd.lib)

Error      77      error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z) already defined in gxinterface.lib(CGxGroupe.obj)      msvcprtd.lib      MyProject

Thank you for any further help you can give!  Very appreciated!
0
 
LVL 14

Expert Comment

by:wayside
ID: 22825520
What is gxinterface.lib? How is gxinterface.lib built?

Brute force solution, not recommended but can work in a pinch:

Project->Properties->Configuration Properties->Linker->Command Line, add "/FORCE:MULTIPLE" to the Additional options box.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 22825568
>>>> Setting the "Use of MFC" setting to "Use MFC in a Shared DLL" does this for you.
It has some advantages when linking against a static MFC library. The compile problems actually were a bug in the MFC headers where the case of static MFC wasn't considered well enough. I spent some days for the same issue some years ago and though it was frustrating, I finally succeeded.


>>>> Error      77      error LNK2005:
I hope, you didn't change to "Use MFC in a Shared DLL" in the meantime? I really made bad experiences when changing this settings for an existing project. Generally, if you want to go for shared MFC dlls, create a new project using the wizard - with the appropriate settings and add all sources of the old project after removing all the default sources. If you move and rename the project files before, you even could create the new project at the same folder using the same name.

The link error is now cause the msvcprtd.lib uses some STL template types same as the MFC static library. It actually is only a ordering issue. First, you should close the project and throw away all temporary files like .ncb, .res, .obj, .aps, .suo, .obj, .bsc, .pch, .ilk . Then make a rebuild all and check whether the errors were gone. If not, you would need to either setup a new project - as I told before - or manipulate the linker settings by forcing some libraries to be linked prior to other libraries. But the last is a bad job with doubtable success.    


0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22825654
>>>> "/FORCE:MULTIPLE"
The LNK2005 issue often is caused by inconstencies between single-threaded and multi-threaded libraries. In the above case we have different template instantiations and it is good possible that different versions of the STL were used by different libraries. The /FORCE:MULTIPLE could make your app use wrong template instantiations what might lead to unpredictable errors. As wayside said it is not recommended, Hence, don't do it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 80
matchUp  challenge 6 53
wait notify demo infinite loop 3 96
Updating statistics with error notification email in SQL server 4 72
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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 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

18 Experts available now in Live!

Get 1:1 Help Now