您的位置:首页 > 其它

VS2003工程转VS2005工程遇到的一些问题

2008-04-01 21:54 176 查看
VS2003工程转VS2005工程:

1.cpp文件include的h文件(头文件)必须和CPP文件在同一文件夹中,否则必须include整个路径

Strmiids.lib(strmiids.obj) : error LNK2005: _IID_IMpeg2Data already defined in
VVGraphBuilder.obj
解决方法:
/FORCE:MULTIPLE

关于DEBUG输出(output)的信息不正确的问题:
先删除掉出错的debug配置,然后建立一个新的debug配置并重新设置debug配置的选项。
关于release下不需要添加头文件math.h就可以使用pow,而debug下必须添加才能够使用。

关于系统头文件中名字冲突引起的编译的问题:

先看编译错误提示信息:

FileDialogEx.cpp
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(261) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(261) : error C2208: 'const int' : no members defined using this type
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(399) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(399) : error C2208: 'const int' : no members defined using this type
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(609) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:/installsoftware/vs2005/vc/atlmfc/include/afxpriv.h(609) : error C2208: 'const int' : no members defined using this type

这几条错误信息表明:FileDialogEx.cpp文件中包含的头文件afxpriv.h的第261、399和609行处有错误,但afxpriv.h是系统文件怎么会有错误呢?
一般这大部分都是因为与其它文件或系统文件发生名字冲突而导致的。

Dib.cpp
e:/product_code_driver_setup/imnetatv_3019_080306/imnetatv/thumbnail/dib.cpp(510) : error C2039: 'OutputDebugStringA' : is not a member of 'CDib'
e:/product_code_driver_setup/imnetatv_3019_080306/imnetatv/thumbnail/dib.h(35) : see declaration of 'CDib'
e:/product_code_driver_setup/imnetatv_3019_080306/imnetatv/thumbnail/dib.cpp(511) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:/product_code_driver_setup/imnetatv_3019_080306/imnetatv/thumbnail/dib.cpp(511) : error C2143: syntax error : missing ';' before '{'
e:/product_code_driver_setup/imnetatv_3019_080306/imnetatv/thumbnail/dib.cpp(511) : error C2447: '{' : missing function header (old-style formal list?)

这几条错误信息表明:Dib.cpp文件的第510和511行的代码有问题。

afxpriv.h文件的第261、399和609行处代码分别为:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

#ifdef _DEBUG
void AssertValid() const;
void Dump(CDumpContext& dc) const;
#endif

#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

Dib.cpp文件的第510和511行的代码为:

#ifdef _DEBUG
void CDib::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif

引起错误的原因:
在工程中有地方包含头文件:dbg.h

//------------------------------------------------------------------------------
// File: Dbg.h
//
// Desc: DirectShow sample code - Helper file for the PSIParser filter.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------

此头文件是微软为directshow提供的帮助文件,里面有如下定义:

#define Dump(tsz) /
OutputDebugString(tsz);

解决办法:将dbg.h头文件中的宏定义改名,如下:

#define Dump1(tsz) /
OutputDebugString(tsz);

不知道这种宏定义是否在整个工程中都有效,即是否相当于全局变量???
可能和头文件编译顺序有关???

这种错误是很难发现的,应该避免~~~

关于另一种链接(LINKER)错误:

AudioDlg.obj : error LNK2019: unresolved external symbol "public: bool __thiscall CDspInfoWnd::SetDspInfo(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SetDspInfo@CDspInfoWnd@@QAE_NAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "protected: void __thiscall CVVTunerDlg::UpdateCounter(void)" (?UpdateCounter@CVVTunerDlg@@IAEXXZ)
VVTunerDlg.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CDspInfoWnd::SetDspInfo(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SetDspInfo@CDspInfoWnd@@QAE_NAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
VVTunerDlg.obj : error LNK2019: unresolved external symbol "public: bool __thiscall CDspInfoWnd::GetDspInfo(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?GetDspInfo@CDspInfoWnd@@QAE_NAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "public: class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __thiscall CVVTunerDlg::GetChannelText(void)" (?GetChannelText@CVVTunerDlg@@QAE?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@XZ)
VVTunerDlg.obj : error LNK2019: unresolved external symbol "public: static class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __fastcall CCtrlMgrGroup::GetSkinDirPath(void)" (?GetSkinDirPath@CCtrlMgrGroup@@SI?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@XZ) referenced in function "protected: class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __thiscall CVVTunerDlg::FindSkinConfigFile(void)" (?FindSkinConfigFile@CVVTunerDlg@@IAE?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@XZ)
VVTunerDlg.obj : error LNK2019: unresolved external symbol "public: class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __thiscall CCtrlMgr::MgrName(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > *)" (?MgrName@CCtrlMgr@@QAE?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@PAV23@@Z) referenced in function "protected: int __thiscall CVVTunerDlg::InitSkin(void)" (?InitSkin@CVVTunerDlg@@IAEHXZ)
SKPanel.obj : error LNK2001: unresolved external symbol "public: class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __thiscall CCtrlMgr::MgrName(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > *)" (?MgrName@CCtrlMgr@@QAE?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@PAV23@@Z)
VVTunerDlg.obj : error LNK2019: unresolved external symbol "public: bool __thiscall CSavedBitmap::AutoLoadBmp(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > *)" (?AutoLoadBmp@CSavedBitmap@@QAE_NPAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "protected: void __thiscall CVVTunerDlg::EnableBackgroundMask(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &,class CRgn *)" (?EnableBackgroundMask@CVVTunerDlg@@IAEXAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@PAVCRgn@@@Z)
SKPanel.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CSavedBitmap::AutoLoadBmp(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > *)" (?AutoLoadBmp@CSavedBitmap@@QAE_NPAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
VVTunerDlg.obj : error LNK2019: unresolved external symbol "public: void __thiscall CSavedBitmap::SetBitmapName(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SetBitmapName@CSavedBitmap@@QAEXAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "protected: void __thiscall CVVTunerDlg::EnableBackgroundMask(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &,class CRgn *)" (?EnableBackgroundMask@CVVTunerDlg@@IAEXAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@PAVCRgn@@@Z)
SKPanel.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSavedBitmap::SetBitmapName(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SetBitmapName@CSavedBitmap@@QAEXAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
xMemMgt.obj : error LNK2019: unresolved external symbol "void __cdecl logPrintf(int,char *,...)" (?logPrintf@@YAXHPADZZ) referenced in function "void __cdecl xMemAllo(unsigned long,unsigned char * *)" (?xMemAllo@@YAXKPAPAE@Z)
Libskindk.lib(UnZipSkin.obj) : error LNK2019: unresolved external symbol _Wiz_SingleEntryUnzip@24 referenced in function "public: long __thiscall CUnZipSkin::Unzip(char const *,char const *)" (?Unzip@CUnZipSkin@@QAEJPBD0@Z)

其中DspInfoWnd.h和DspInfoWnd.cpp文件中分别包含有类CDspInfoWnd及其成员函数SetDspInfo与GetDspInfo等的定义和实现:

bool SetDspInfo( CString & string);
bool GetDspInfo(CString &string);
void GetDspFont(LOGFONT &lf);
void SetDspFont(LOGFONT lf);

bool CDspInfoWnd::SetDspInfo(CString &string)
{
if( !::IsWindow(m_hWnd ) )
return false;

m_DspString = string;

PrepareDspInfo();

CClientDC dc(this);
DrawDspInfo(&dc);

if( m_pToolTip )
m_pToolTip->UpdateTipText(string, this);

return true;
}

bool CDspInfoWnd::GetDspInfo(CString &string)
{
if( !::IsWindow(m_hWnd ) )
return false;

string = m_DspString;
return true;
}

void CDspInfoWnd::GetDspFont(LOGFONT &lf)
{
memset(&lf, 0, sizeof(LOGFONT));
if(m_pDspFont)
m_pDspFont->GetLogFont(&lf);
}

void CDspInfoWnd::SetDspFont(LOGFONT lf)
{
if(m_pDspFont)
delete m_pDspFont;
m_pDspFont = new CAutoFont(lf);
}

其中导致错误出现的函数CVVTunerDlg::UpdateCounter的实现如下:

void CVVTunerDlg::UpdateCounter(void)
{
if(!m_bPauseTS)
{
m_iCounterSec10 += m_iCounterSec1/10;
m_iCounterMinute1 += m_iCounterSec10/6;
m_iCounterMinute10 += m_iCounterMinute1/10;
m_iCounterHour1 += m_iCounterMinute10/6;
m_iCounterHour10 += m_iCounterHour1/10;

m_iCounterSec1 %= 10;
m_iCounterMinute1 %= 10;
m_iCounterHour1 %=10;
m_iCounterSec10 %= 6;
m_iCounterMinute10 %=6;
m_iCounterHour10 %=10;

//// Format the Time counter
CString str;
str.Format("%d%d:%d%d:%d%d",
m_iCounterHour10,m_iCounterHour1,
m_iCounterMinute10,m_iCounterMinute1,
m_iCounterSec10,m_iCounterSec1);
//pszA = ( LPCSTR )str;
//Bbmpfile.Append(pszA);
// Mask ASkin
//m_pStaticCounter->SetCaption(Bbmpfile);
//m_pSkinVisual->Refresh();
LOGFONT lf;
m_SkinDspInfoTimeCounter.GetDspFont(lf);
lf.lfWeight=FW_BLACK;
lf.lfHeight = 12;
lf.lfWidth= 6;
m_SkinDspInfoTimeCounter.SetDspFont(lf);

m_SkinDspInfoTimeCounter.SetDspInfo(str);

m_iCounterSec1++;
}

m_iCountTime++;

}

类CDspInfoWnd的成员函数SetDspInfo与GetDspInfo明明已经实现了,为什么调用会出现链接错误呢?
通过比较发现:在函数CVVTunerDlg::UpdateCounter中调用类CDspInfoWnd的成员函数GetDspFont和SetDspFont是正确的,没有出现
链接错误,那到底是什么原因呢?

编译错误提示信息中的几个相似的字符串“(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)”
提醒了我,这些字符串要么出现在出错函数的参数位置,要么出现在出错函数的返回值位置,那么是不是因为调用和声明不一致造成的呢?

但发现函数的参数是CString,调用的时候也是用CString变量作为参数,没有错误啊?但编译错误提示信息:
unresolved external symbol "public: bool __thiscall CDspInfoWnd::SetDspInfo(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SetDspInfo@CDspInfoWnd@@QAE_NAAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
明明讲SetDspInfo没有实现啊?忽然想起CString有两个不同的版本,分别包含在cstringt.h和atlstr.h头文件中。
那么是不是声明和定义时的SetDspInfo中CString和调用时的CString不同呢?

试了一下在DspInfoWnd.h文件中包含头文件atlstr.h或头文件cstringt.h,问题都可以解决。但有时候不包含也不会出现链接错误???
但如果调用函数存在的文件包含的string头文件和声明定义文件包含的string头文件不同,肯定会出现上面的链接错误。

关于错误:
StdAfx.cpp
D:/InstallSoftware/VS2005/VC/atlmfc/include/afxver_.h(77) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds

错误原因:
因为使用的是动态链接MFC选项,即Use MFC in a Shared DLL,系统定义了_AFXDLL,可以在afxver_.h(77)处找到定义的相关语句:

// _AFXEXT implies _AFXDLL
#if defined(_AFXEXT) && !defined(_AFXDLL)
#define _AFXDLL
#endif

#if defined(_AFXDLL) && !defined(_DLL)
#error Please use the /MD switch for _AFXDLL builds
#endif

#if defined(_AFXDLL) && !defined(_MT)
#error Please use the /MD switch (multithreaded DLL C-runtime)
#endif

这些语句的作用是:
如果我们设置编译器为动态链接MFC(即Use MFC in a Shared DLL)---->对应于语句 #if defined(_AFXDLL)
且我们没有设置编译器的Runtime library为DLL型,即/MD或/MDd --->对应于语句 && !defined(_DLL)
那么编译时将给出编译错误“Please use the /MD switch for _AFXDLL builds”作为提示信息 --->对应于语句 #error Please use the /MD switch for _AFXDLL builds

另外两个预编译处理的作用类似~~

注意Runtime library的选项含义如下:

Multi-threaded (/MT):是指使用静态方式链接MFC库,Input中包含的C Run-Time Libraries (CRT)应该为静态链接release版本的libcmt.lib
Multi-threaded Debug (/MTd):是指使用静态方式链接MFC库,Input中包含的C Run-Time Libraries (CRT)应该为静态链接debug版本的libcmtd.lib
Multi-threaded DLL (/MD):是指使用动态方式链接MFC,Input中包含的C Run-Time Libraries (CRT)应该为动态链接release版本的msvcrt.lib
Multi-threaded Debug DLL(/MDd):是指使用动态方式链接MFC,Input中包含的C Run-Time Libraries (CRT)应该为debug版本的msvcrtd.lib

D代表是用静态方式链接MFC库,还是用动态方式。
d代表是debug是debug版本的C运行时库,还是release版本的C运行时库。

经验:一定要仔细,看清楚编译错误的提示信息!!!

VS2003 Lib在VS2005工程中无法使用,需要在VS2005中重新编译生成VS2005 Lib
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: