unresolved external symbol

I' m creating a simple MFC text editor in VS2010 in order to learn C++ and I've hit a bit of a stumbling block....

Specifically, I get the following error in my build log:

1
2
3
4
5
6
7
8
9
10
  1>  Generating Code...
1>Link:
1>     Creating library C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.lib and object C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.exp
1>EmergenceDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall CEmergenceCntrItem::CEmergenceCntrItem(struct _reobject *,class CEmergenceDoc *)" (??0CEmergenceCntrItem@@QAE@PAU_reobject@@PAVCEmergenceDoc@@@Z) referenced in function "public: virtual class CRichEditCntrItem * __thiscall CEmergenceDoc::CreateClientItem(struct _reobject *)const " (?CreateClientItem@CEmergenceDoc@@UBEPAVCRichEditCntrItem@@PAU_reobject@@@Z)
1>C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.dll : fatal error LNK1120: 1 unresolved externals
1> 
1>Build FAILED.
1>
1>Time Elapsed 00:00:06.52
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========


Below are all the files in which CEmergenceCntrItem appears....

cntritem.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "afxrich.h"
// #include "Resource.h"
class CEmergenceDoc;
class CEmergenceView;

class CEmergenceCntrItem : public CRichEditCntrItem
{
	DECLARE_SERIAL(CEmergenceCntrItem)

// Constructors
public:
	CEmergenceCntrItem(REOBJECT* preo = NULL, CEmergenceDoc* pContainer = NULL);
		// Note: pContainer is allowed to be NULL to enable IMPLEMENT_SERIALIZE.
		//  IMPLEMENT_SERIALIZE requires the class have a constructor with
		//  zero arguments.  Normally, OLE items are constructed with a
		//  non-NULL document pointer.

// Attributes
public:
	CEmergenceDoc* GetDocument()
		{ return (CEmergenceDoc*)COleClientItem::GetDocument(); }
	CEmergenceView* GetActiveView()
		{ return (CEmergenceView*)COleClientItem::GetActiveView(); }

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CWordPadCntrItem)
	public:
	protected:
	//}}AFX_VIRTUAL

// Implementation
public:
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif
};


EmergenceView.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "Emergence.h"
#endif
#include "EmergenceDoc.h"
#include "EmergenceView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CEmergenceView

IMPLEMENT_DYNCREATE(CEmergenceView, CRichEditView)

BEGIN_MESSAGE_MAP(CEmergenceView, CRichEditView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CEmergenceView::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
END_MESSAGE_MAP()

// CEmergenceView construction/destruction

CEmergenceView::CEmergenceView()
{
	// TODO: add construction code here

}

CEmergenceView::~CEmergenceView()
{
}

BOOL CEmergenceView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CEmergenceView drawing

void CEmergenceView::OnDraw(CDC* /*pDC*/)
{
	CEmergenceDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
}


// CEmergenceView printing


void CEmergenceView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CEmergenceView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEmergenceView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEmergenceView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CEmergenceView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CEmergenceView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CEmergenceView diagnostics

#ifdef _DEBUG
void CEmergenceView::AssertValid() const
{
	CView::AssertValid();
}

void CEmergenceView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEmergenceDoc* CEmergenceView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmergenceDoc)));
	return (CEmergenceDoc*)m_pDocument;
}
#endif //_DEBUG 


EmergenceDoc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdafx.h"
#include "Emergence.h"

#include "EmergenceDoc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

extern BOOL AFXAPI AfxFullPath(LPTSTR lpszPathOut, LPCTSTR lpszFileIn);
extern UINT AFXAPI AfxGetFileTitle(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);

#ifndef OFN_EXPLORER
#define OFN_EXPLORER 0x00080000L
#endif

#include "cntritem.h"

///////////////////////////////////////////////////////////////////////////
// CMyWordDoc

IMPLEMENT_DYNCREATE(CEmergenceDoc, CRichEditDoc)

BEGIN_MESSAGE_MAP(CEmergenceDoc, CRichEditDoc)
    //{{AFX_MSG_MAP(CMyWordDoc)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    // Enable default OLE container implementation
    ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, 
        CRichEditDoc::OnUpdateEditLinksMenu)
    ON_COMMAND(ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks)
    ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, 
        ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()

///////////////////////////////////////////////////////////////////////////
// CMyWordDoc construction/destruction

CEmergenceDoc::CEmergenceDoc()
{
}

CEmergenceDoc::~CEmergenceDoc()
{
}

BOOL CEmergenceDoc::OnNewDocument()
{
    if (!CRichEditDoc::OnNewDocument())
        return FALSE;
    return TRUE;
}
CRichEditCntrItem* CEmergenceDoc::CreateClientItem(REOBJECT* preo) const
{
    return new CEmergenceCntrItem(preo, (CEmergenceDoc*) this);
}

///////////////////////////////////////////////////////////////////////////
// CMyWordDoc serialization

void CEmergenceDoc::Serialize(CArchive& ar)
{
    CRichEditDoc::Serialize(ar);
}

///////////////////////////////////////////////////////////////////////////
// CMyWordDoc diagnostics

#ifdef _DEBUG
void CEmergenceDoc::AssertValid() const
{
    CRichEditDoc::AssertValid();
}

void CEmergenceDoc::Dump(CDumpContext& dc) const
{
    CRichEditDoc::Dump(dc);
}
#endif //_DEBUG 


cntritem.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include "Emergence.h"

#include "EmergenceDoc.h"
#include "EmergenceView.h"
#include "cntritem.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWordPadCntrItem implementation

IMPLEMENT_SERIAL(CEmergenceCntrItem, CRichEditCntrItem, 0)

CEmergenceCntrItem::CEmergenceCntrItem(REOBJECT *preo, CEmergenceDoc* pContainer)
	: CRichEditCntrItem(preo, pContainer)
{
}

/////////////////////////////////////////////////////////////////////////////
// CWordPadCntrItem diagnostics

#ifdef _DEBUG
void CEmergenceCntrItem::AssertValid() const
{
	CRichEditCntrItem::AssertValid();
}

void CEmergenceCntrItem::Dump(CDumpContext& dc) const
{
	CRichEditCntrItem::Dump(dc);
}
#endif 


Any help would be greatly appreciated.
Could it be that somehow, cntritem.cpp is not considered to be a dependency/part of the project by the compiler?
Hi xismn, thanks for replying.

Assuming that cntritem.cpp is not is not considered to be a dependency/part of the project by the compiler, how would you make it so that it is?
Yes, this was the case. Just copied cntritem.cpp and cntritem.h to resources folder as well.
So, it's working? Sorry for not replying sooner.
Yup! Thanks.
Topic archived. No new replies allowed.