Thursday, April 24, 2014

Linking error LNK2019: unresolved external symbol


Example of an error:

error LNK2019: unresolved external symbol "__declspec(dllimport) protected: virtual __cdecl SECMDIFrameWnd::~SECMDIFrameWnd(void)" (__imp_??1SECMDIFrameWnd@@MEAA@XZ) referenced in function "public: virtual __cdecl ACMainFrame::~ACMainFrame(void)" (??1ACMainFrame@@UEAA@XZ)

How do you fix this error?

Let's say you have checked the followings already:
1. The library file containing the symbol above is in the path.
2. The library files and your build are in 32-bit or 64-bit. You cannot link a 64-bit build to a 32-bit libraries.
3. Make sure your release/debug build is linking to the release/debug build of the libraries.

Next you need to check if  the symbol showed in the error is in the library file.

To check if  symbol virtual __cdecl SECMDIFrameWnd::~SECMDIFrameWnd(void) is in the library, you can use the dllexportviewer program.
You can load the library file into the dllexportviewer program to see all of its symbols. Then you can locate/search if the symbol existed.

Let's say you cannot find it. You can only see this symbol in the library.

virtual __thiscall SECMDIFrameWnd::~SECMDIFrameWnd(void)

Obviously there is a mismatch. The mismatch here indicates that the calling conventions are different. Now you need to know why your program is looking for the cdecl calling convention instead of __thiscall.

One problem is you could have the calling convention set incorrectly in your project settings.
If that's the case, you can check the project settings and change it to use the _fastcall calling convention to fix the issue.







No comments: