问题
I am trying to run this program on Visual Studio 2013, but when I include an object - myparser.obj I am getting the following error:
1>MyParser.obj : error LNK2001: unresolved external symbol "class ATL::CTraceCategory ATL::atlTraceException" (?atlTraceException@ATL@@3VCTraceCategory@1@A)
1>MyParser.obj : error LNK2001: unresolved external symbol "public: static class ATL::CTrace ATL::CTrace::s_trace" (?s_trace@CTrace@ATL@@2V12@A)
1>MyParser.obj : error LNK2019: unresolved external symbol _AtlTraceVA referenced in function "public: void __cdecl ATL::CTrace::TraceV(char const *,int,unsigned long,unsigned int,char const *,char *)const " (?TraceV@CTrace@ATL@@QBAXPBDHKI0PAD@Z)
Is there something wrong with the myparser or is it something else?
Code4A.h
#include <afxwin.h>
#define IDC_BUTTON 501
#define nInput 6
extern double parse(CString,int,double [],int []);
class CCode4A : public CFrameWnd
{
protected:
typedef struct
{
CString label,item;
CPoint hm;
CEdit ed;
CRect rc,display;
} INPUT;
INPUT input[nInput+1];
CStatic result;
CFont Arial80;
CButton btn;
int idc;
public:
CCode4A();
~CCode4A();
afx_msg void OnPaint(),OnButton();
DECLARE_MESSAGE_MAP()
};
class CMyWinApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
Code4A.cpp
#include "Code4A.h"
CMyWinApp MyApplication;
BOOL CMyWinApp::InitInstance()
{
CCode4A* pFrame = new CCode4A;
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CCode4A,CFrameWnd)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON,OnButton)
END_MESSAGE_MAP()
CCode4A::CCode4A()
{
Create(NULL,"Code4A: Scientific Calculator",
WS_OVERLAPPEDWINDOW,CRect(0,0,700,350),NULL);
Arial80.CreatePointFont(80,"Arial");
idc=301;
input[0].hm=CPoint(200,20);
for (int i=1;i<=nInput;i++)
input[i].hm=CPoint(input[0].hm.x+10,input[0].hm.y+50+(i-1)*30);
input[1].label="t";
input[2].label="u";
input[3].label="v";
input[4].label="x";
input[5].label="y";
input[6].label="Expression";
btn.Create("Compute",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
CRect(CPoint(input[0].hm.x,input[0].hm.y+5),CSize(100,20)),
this,IDC_BUTTON);
for (i=1;i<=nInput-1;i++)
input[i].ed.Create(WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(input[i].hm.x+70,input[i].hm.y,input[i].hm.x+150,
input[i].hm.y+20),this,idc++);
input[nInput].ed.Create(WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(input[nInput].hm.x+70,input[nInput].hm.y,
input[nInput].hm.x+350,input[nInput].hm.y+20),this,idc++);
result.Create("",WS_CHILD | WS_VISIBLE | SS_CENTER | WS_BORDER,
CRect(input[nInput].hm.x+50,input[nInput].hm.y+50,
input[6].hm.x+150,input[6].hm.y+70),this,idc++);
}
CCode4A::~CCode4A()
{
}
void CCode4A::OnPaint()
{
CPaintDC dc(this);
CString str;
dc.SelectObject(Arial80);
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(100,100,100));
for (int i=1;i<=nInput;i++)
dc.TextOut(input[i].hm.x,input[i].hm.y,input[i].label);
dc.TextOut(input[6].hm.x,input[6].hm.y+50,"Result");
}
void CCode4A::OnButton()
{
CString str;
int i,psi[nInput+1];
double z,psv[nInput+1];
for (i=1;i<=nInput;i++)
input[i].ed.GetWindowText(input[i].item);
psi[1]=19;
psi[2]=20;
psi[3]=21;
psi[4]=23;
psi[5]=24;
for (i=1;i<=nInput;i++)
psv[i]=atof(input[i].item);
z=parse(input[nInput].item,5,psv,psi);
str.Format("%lf",z);
result.SetWindowText(str);
}
回答1:
Check your project settings, you are missing linker input to atls.lib.
Set the project to /NODEFAULTLIB and explicitly link it to atls.lib
/NODEFAULTLIB
回答2:
include "atlbase.h"
should fix the problem
来源:https://stackoverflow.com/questions/27612395/error-lnk2001-unresolved-external-symbol-class-atlctracecategory-atlatltra