Tag Archives: visual studio

C++ error LNK2001: unresolved external symbol

A quick Visual C++ tip to help those who get stuck on this problem like I did. If you find yourself getting errors like this:

foo.obj : error LNK2001: unresolved external symbol "public: __thiscall MyMatrix::~MyMatrix(void)" (??1MyMatrix@@QAE@XZ)
foo.obj : error LNK2001: unresolved external symbol "public: __thiscall MyMatrix::MyMatrix(class MyMatrix const &)" (??0MyMatrix@@QAE@ABV0@@Z)
fooData.obj : error LNK2001: unresolved external symbol "public: __thiscall MyMatrix::MyMatrix(unsigned int,unsigned int)" (??0MyMatrix@@QAE@II@Z)
bar.obj : error LNK2001: unresolved external symbol "public: class MyMatrix & __thiscall MyMatrix::resize(unsigned int,unsigned int)" (?resize@MyMatrix@@QAEAAV1@II@Z)
.Release2MCProject-32bit-noxlw.exe : fatal error LNK1120: 4 unresolved externals

it could mean that certain methods are declared but not defined. In other words there may be methods in the header files that have no implementations in cpp files. Above we can see that a destructor, two constructors and a resize call are what the compiler’s complaining about. This was because those methods had not been implemented but were in the header file.

Though the really odd thing is that this project was compiling in 32 bit mode and when I tried to port it to 64 bit mode suddenly these errors crept up. I don’t know why these errors didn’t occur in 32 bit mode. Must be yet another compiling intricacy that I’m not aware of.

C++ can be a nightmare compared to higher level languages.

msvcprtd.lib(MSVCP100D.dll) : fatal error LNK1112: module machine type ‘X86’ conflicts with target machine type ‘x64’

If you get the above error when trying to build a project in 64 bits or port a 32 bits project to 64 bits in Visual Studio 2010 go to Project Property Pages > Configuration Properties > VC++ Directories > Library Directories and make sure you have the appropriate 64 bit directories in there and not the 32 bit equivalents.

I had to change my Library Directories entry from:

$(VCInstallDir)lib;$(VCInstallDir)atlmfclib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)lib;

to:

$(VCInstallDir)libamd64;$(VCInstallDir)atlmfclibamd64;$(WindowsSdkDir)libx64;

In fact check all entries under Project Property Pages > Configuration Properties > VC++ Directories to see they’re 64 bit paths. If the above doesn’t work try creating a new project in VS, converting it from 32bit to 64bit and if it builds use it as a reference and compare with the real project you’re trying to convert to 64bit. Sync the differences and see where you get to. That’s what I did.

This has wasted so much of my time and has been so difficult to track down that I just had to blog it in case it saved other hours, days or even weeks. There are many variants of the above error each of which could be due to different causes. This post only relates to the error prefixed with msvcprtd.lib(MSVCP100D.dll).

Did this help you out? Let me know in the comments.