19

I have problem with compiling my project via visual studio 2013. I got this linker error:

LINK : fatal error LNK1104: cannot open file 'nafxcwd.lib'

According to this page, I must use MFC in shared library. But I don't use MFC at all.
All my libraries and main project compiled using Use Standard Windows Libraries settings. This problem occurs only when I try to build project via Visual Studio 2013 toolchain, but it successfully built with Visual Studio 2010 toolchain.

P.S. project has been moved from Visual Studio 6.0 to Visual Studio 2013.

Himanshu
  • 4,327
  • 16
  • 31
  • 39
user922871
  • 435
  • 2
  • 6
  • 17
  • 4
    No, you are definitely using MFC. Probably some .lib you forgot about long ago. You are paying an overdue technical debt, the flavor of the MFC library you need was [deprecated in VS2013](http://blogs.msdn.com/b/vcblog/archive/2013/07/08/mfc-support-for-mbcs-deprecated-in-visual-studio-2013.aspx?PageIndex=3). You can still get the library as a separate download, don't count on that working for much longer. – Hans Passant Jun 28 '14 at 16:09
  • 6
    Thanks, @Hans. FYI: I found the download here: http://www.microsoft.com/en-us/download/details.aspx?id=40770 – BrainSlugs83 Dec 24 '14 at 02:11
  • @BrainSlugs83 Will installing those mfc libraries work when using the visual studio command line console to compile? – James Wierzba Mar 14 '16 at 18:30
  • OP's link to microsoft has gone bad. – rsaxvc Jun 05 '18 at 23:01

4 Answers4

3

It appears that in Microsoft Visual C++ 6.0 Standard Edition does not support statically linking with the MFC libraries as the Microsoft page says . But in Visual Studio 2013 you can link staticaly with Microsoft Libraries . Check this link https://support.microsoft.com/en-us/kb/243458 in order to solve your problem.

From The Microsoft Site :

To change your MFC project setting to link dynamically to the MFC libraries, perform the following steps: Open your MFC project.

  1. From the Project menu, click Settings.
  2. In the Settings For combo box, select All Configurations. Click the General tab. If it is not visible, use the tab scroll buttons to scroll to the left.
  3. In the Microsoft Foundation Classes combo box, select Use MFC in a Shared DLL. Click OK to save the changes.
1

I had the same issue except it compiled on one machine but not another. Solved by installing the Multibyte MFC Library for Visual Studio 2013 as suggested in: MBCS Error building MFC C++ project with Visual Studio

kristian mo
  • 1,476
  • 2
  • 11
  • 19
0

To isolate the culprit that consumes MFC, link with /VERBOSE and search the output for nafxcwd. Most probably it would appear after a /DEFAULTLIB directive - just note which library was loaded exactly before the directive.

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101
0

Going through updating a VS 2008 project which did not use MFC at all, I faced this same problem and fixed it doing these three steps. Please see the shot to have a glance on the properties of the project (VS 2008) highlighted.

enter image description here

Step-1

Please add this line #define _AFXDLL in your stdafx.h file

#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers

#define _AFXDLL

Step-2

Go to your VS 2013 solution and open "Project Properties -> C/C++ -> Code Generation -> Runtime Library" and change the value to Multi-threaded Debug DLL (/MDd) (adjust your release configuration to Multi-threaded DLL (/MD), once you will complete these two steps you will start getting this linking error

error LNK1104: cannot open file 'mfc120d.lib'

Now, here you have to set the "Character Set" for your project to Unicode instead of _MBCS

Step-3

Now open "Project Properties -> General -> Project Defaults -> Character Set" and change the value to Use Unicode Character Set, now this part requires little more patience and work, you have to change your string traits to either wchar_t or TCHAR in your source files.

Hope it would solve your problem.

A.B.
  • 1,554
  • 1
  • 14
  • 21