评论

收藏

[C++] VC6使用#import指令出现LNK2005错误

编程语言 编程语言 发布于:2021-07-31 10:26 | 阅读数:470 | 评论:0

以前在VC中使用TeeChart都是使用的ClassWizard添加控件到工程中,每次要添加上百个文件很是麻烦。今天试着用#import指令,却出现了一些麻烦。
步骤是这样的:
1、首先在StdAfx.h中添加:
    #import "TeeChart5.ocx" no_namespace no_implementation
2、然后在StdAfx.cpp中添加:
    #import "TeeChart5.ocx" no_namespace implementation_only
3、修改CTeeTestDlg类的定义
 ITChartPtr m_pTChart;
 CTeeTestDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
 //{{AFX_DATA(CTeeTestDlg)
 enum { IDD = IDD_TEETEST_DIALOG };
 CWnd m_TChart;
 //}}AFX_DATA

4、修改CTeeTestDlg::DoDataExchange
void CTeeTestDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CTeeTestDlg)
 DDX_Control(pDX, IDC_TCHART1, m_TChart);
 //}}AFX_DATA_MAP
 if (!pDX->m_bSaveAndValidate) // Link Chart pointer to control window
  m_pTChart = m_TChart.GetControlUnknown();
}
5、在一个按钮中添加了这么几句:
 // TODO: Add extra validation here
 for(int i = 0; i < 100; i++)
 {
  m_pTChart->Series(0)->asPolar->AddPolar(i * 10, i * 10, "", RGB(255, 0, 0));
  m_pTChart->Series(1)->asPolar->AddPolar(i * 15, i * 15, "", RGB(0, 255, 0));
 }
编译正确,但出现链接错误。

Linking...
TeeTestDlg.obj : error LNK2005: "public: class _com_ptr_t<class _com_IIID<struct ISeries,&struct __s_GUID _GUID_b6c104ac_fb89_11d4_93c9_006008a7eed4> > __thiscall ITChart::Series(long)" (?Series@ITChart@@QAE?AV?$_com_ptr_t@V?$_com_IIID@UISeries@@$1?
_GUID_b6c104ac_fb89_11d4_93c9_006008a7eed4@@3U__s_GUID@@A@@@@J@Z) already defined in StdAfx.obj
TeeTestDlg.obj : error LNK2005: "public: class _com_ptr_t<class _com_IIID<struct IPolarSeries,&struct __s_GUID _GUID_b6c1050b_fb89_11d4_93c9_006008a7eed4> > __thiscall ISeries::GetasPolar(void)" (?GetasPolar@ISeries@@QAE?AV?$_com_ptr_t@V?$_com_IIID@
UIPolarSeries@@$1?_GUID_b6c1050b_fb89_11d4_93c9_006008a7eed4@@3U__s_GUID@@A@@@@XZ) already defined in StdAfx.obj
TeeTestDlg.obj : error LNK2005: "public: long __thiscall IPolarSeries::AddPolar(double,double,class _bstr_t,unsigned long)" (?AddPolar@IPolarSeries@@QAEJNNV_bstr_t@@K@Z) already defined in StdAfx.obj
Debug/TeeTest.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
TeeTest.exe - 4 error(s), 0 warning(s)

如果注释掉for循环中一句,则可以正确链接。而同样的程序在VS2003下却是正常的。真是奇怪。


关注下面的标签,发现更多相似文章