Major Linker Error in VS 2003 LNK2019  
Author Message

PostPosted: Visual C++ General, Major Linker Error in VS 2003 LNK2019 Top

Hi All,

I am able to build the application in Visual studio 6.0. But when i try to compile in the Visual studio 2003 or 2005 below LNK2019 error is coming.

I have check in the window subsystem , code generation option and also i have added the import type of CString derived class as mentioned on Microsoft site for solution of LNK2019 error on the Microsoft KB article.

Till now not able to solve.

Please help me immediately to solve the same.





.\Release/D39Utility.exe : fatal error LNK1120: 2 unresolved externals


Visual C++14  
Alexandre N

PostPosted: Visual C++ General, Major Linker Error in VS 2003 LNK2019 Top

Hi vivekanand

I had the same problem. It seems I've found the reason in my case. The exported function had CString as return value (or maybe as input value) but it was not compiled with declaration __declspec(dllexport). Allthough it was declared in the h-file properly, but this h-file was not used during the compilation of the DLL.

Function was declared in CryptStr.h and looked like this


      #define SHEXPCOMMON_DECL __declspec(dllexport)


      #define SHEXPCOMMON_DECL __declspec(dllimport)


SHEXPCOMMON_DECL CString CryptString1(const CString& csA);

But in cpp-file I had the following:

#include "stdafx.h"
CString CryptString1(const CString& csA){ ..//body...}

Error looked like this

I added one line in CryptStr.cpp (see below)
#include "stdafx.h"
#include "CryptStr.h" // THIS Line was added

After this the everything was compiled and linked Ok

Regards AlexandreN


PostPosted: Visual C++ General, Major Linker Error in VS 2003 LNK2019 Top


Thanks for your reply on this.

As you told the function us is exported in library and imported in the application as defined in the h- file "CryptStr.h".

In my case :

My library is called within a class not as a single function. This class is exported using the macro

AFX_EXT_CLASS in library. While using this calss in application included the h-file and macro uses is


Below is the scan of piece of code.

class AFX_EXT_CLASS CUB_RasLib: public CWnd



void Ras_Connect(CString cstrDialNum, CString cstrID, CString cstrPW);


The function Ras_connect() is imported from class in the application and exported while in library.

Till now i am getting the LNK2019 linker error.

Please help me solve the same immediately.

This is very urgent for me waiting for your reply.



Alexandre N

PostPosted: Visual C++ General, Major Linker Error in VS 2003 LNK2019 Top

Hi Vivek

I would recommend you to check what value has in your library the constant AFX_EXT_CLASS

Depending on definition or not definition of

AFX_EXT_DATA and _AFXEXT it may have one for the following values


Simply try to open afxv_dll.h from your project and have a look on AFX_CLASS_EXPORT. If you use MS VS 2005, put cursor on the constant AFX_EXT_CLASS and press F12. afxv_dll.h will open in corresponding position.

It will probably look as follows:

// default AFX_EXT_DATA and AFX_EXT_DATADEF macros for using or

// creating MFC extension DLLs, depending on _AFX_EXT_IMPL

// AFX_EXT_CLASS can be used to import or export entire classes

// in an extension DLL without the hassle of creating a .DEF file

// with decorated names.

#ifndef AFX_EXT_DATA

#ifdef _AFXEXT












If so, it will mean you have it defined in the library as import, but you need it as export.

I call sometimes libraries from libraries and use definitions like this

#ifdef __EXTCOL_PRJ__

#define EXTCOL_DECL __declspec(dllexport)


#define EXTCOL_DECL __declspec(dllimport)


class EXTCOL_DECL CExtUtil {<class body>};

in stdafx.h of the library I correspondingly define the constant.

So I can include .h files of one library into classes of other library.

Best regards