在 MFC 6.0 中构建 MFC 4.1 项目时出错
Error while building MFC 4.1 project in MFC 6.0
我下载了一个最初用MFC 4.1开发的项目。我正在尝试在 MFC 6.0 中构建该项目。当我使用 Open WorkSpace
打开它并构建它时,出现以下错误。
Link : fatal error LNK1104: cannot open file "mfc42ud.lib"
在 Internet 上,我找到了解决此错误的解决方案,方法是从项目设置中忽略此库。我这样做了,然后 mfcs42ud.lib
文件出现了类似行的另一个错误。我也修好了。
当我将两个 .lib 文件添加到忽略列表并构建它时,我收到如下所示的 901 错误....
--------------------Configuration: doodads - Win32 Unicode Debug-------------------- Linking... doodads.obj :
error LNK2001:
unresolved external symbol __afxForceEXCLUDE ADDRESS.OBJ : error
LNK2001: unresolved external symbol __afxForceEXCLUDE expose.obj :
error LNK2001: unresolved external symbol __afxForceEXCLUDE
progress.obj : error LNK2001: unresolved external symbol
__afxForceEXCLUDE MaskDlg.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE SETKEY.OBJ : error LNK2001: unresolved
external symbol __afxForceEXCLUDE SPINNER.OBJ : error LNK2001:
unresolved external symbol __afxForceEXCLUDE stats.obj : error
LNK2001: unresolved external symbol __afxForceEXCLUDE ANIME.OBJ :
error LNK2001: unresolved external symbol __afxForceEXCLUDE STDAFX.OBJ
: error LNK2001: unresolved external symbol __afxForceEXCLUDE
MAINFRM.OBJ : error LNK2001: unresolved external symbol
__afxForceEXCLUDE DODADDOC.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE DoDadvw.obj : error LNK2001: unresolved
external symbol __afxForceEXCLUDE doodads.obj : error LNK2001:
unresolved external symbol __afxForceSTDAFX ADDRESS.OBJ : error
LNK2001: unresolved external symbol __afxForceSTDAFX expose.obj :
error LNK2001: unresolved external symbol __afxForceSTDAFX
progress.obj : error LNK2001: unresolved external symbol
__afxForceSTDAFX MaskDlg.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX SETKEY.OBJ : error LNK2001: unresolved
external symbol __afxForceSTDAFX SPINNER.OBJ : error LNK2001:
unresolved external symbol __afxForceSTDAFX stats.obj : error LNK2001:
unresolved external symbol __afxForceSTDAFX ANIME.OBJ : error LNK2001:
unresolved external symbol __afxForceSTDAFX STDAFX.OBJ : error
LNK2001: unresolved external symbol __afxForceSTDAFX MAINFRM.OBJ :
error LNK2001: unresolved external symbol __afxForceSTDAFX
DODADDOC.OBJ : error LNK2001: unresolved external symbol
__afxForceSTDAFX DoDadvw.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX
这是供您参考的代码文件。
Add.h
// ADD.H - Header file for your Internet Server
// add Extension
#include "resource.h"
class CAddExtension : public CHttpServer
{
public:
CAddExtension();
~CAddExtension();
// Overrides
// ClassWizard generated virtual function overrides
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//{{AFX_VIRTUAL(CAddExtension)
public:
virtual BOOL GetExtensionVersion(HSE_VERSION_INFO* pVer);
//}}AFX_VIRTUAL
// TODO: Add handlers for your commands here.
// For example:
void Default(CHttpServerContext* pCtxt,
LPCTSTR pstrOp1, LPCTSTR pstrOp2);
DECLARE_PARSE_MAP()
//{{AFX_MSG(CAddExtension)
//}}AFX_MSG
};
Add.cpp
// ADD.CPP - Implementation file for your Internet Server
// add Extension
#include "stdafx.h"
#include "add.h"
#include <stdio.h>
///////////////////////////////////////////////////////////////////////
// command-parsing map
BEGIN_PARSE_MAP(CAddExtension, CHttpServer)
// TODO: insert your ON_PARSE_COMMAND() and
// ON_PARSE_COMMAND_PARAMS() here to hook up your commands.
// For example:
ON_PARSE_COMMAND(Default, CAddExtension, ITS_PSTR ITS_PSTR)
ON_PARSE_COMMAND_PARAMS("opone=~ optwo=~")
DEFAULT_PARSE_COMMAND(Default, CAddExtension)
END_PARSE_MAP(CAddExtension)
///////////////////////////////////////////////////////////////////////
// The one and only CAddExtension object
CAddExtension theExtension;
///////////////////////////////////////////////////////////////////////
// CAddExtension implementation
CAddExtension::CAddExtension()
{
}
CAddExtension::~CAddExtension()
{
}
BOOL CAddExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
// Call default implementation for initialization
CHttpServer::GetExtensionVersion(pVer);
// Load description string
TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
_tcscpy(pVer->lpszExtensionDesc, sz);
return TRUE;
}
///////////////////////////////////////////////////////////////////////
// CAddExtension command handlers
void CAddExtension::Default(CHttpServerContext* pCtxt,
LPCTSTR pstrOp1, LPCTSTR pstrOp2)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
int nOp1;
int nOp2;
if (*pstrOp1 != '~' && *pstrOp2 != '~')
{
nOp1 = atoi(pstrOp1);
nOp2 = atoi(pstrOp2);
char sz[1024];
sprintf(sz, "The result is: %d\n", nOp1 + nOp2);
*pCtxt << sz;
}
else
{
*pCtxt << "<FORM ACTION=\"http://mooseboy/add.dll\" METHOD=\"GET\">";
*pCtxt << "Enter the first number: <INPUT TYPE=\"text\" NAME=\"opone\" VALUE=\"0\" SIZE=10><p>";
*pCtxt << "Enter the second number: <INPUT TYPE=\"text\" NAME=\"optwo\" VALUE=\"0\" SIZE=10><p>";
*pCtxt << "<p> <INPUT TYPE = \"SUBMIT\" VALUE=\"Add it up\">";
*pCtxt << "</FORM>";
}
EndContent(pCtxt);
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CAddExtension, CHttpServer)
//{{AFX_MSG_MAP(CAddExtension)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
///////////////////////////////////////////////////////////////////////
// If your extension will not use MFC, you'll need this code to make
// sure the extension objects can find the resource handle for the
// module. If you convert your extension to not be dependent on MFC,
// remove the comments arounn the following AfxGetResourceHandle()
// and DllMain() functions, as well as the g_hInstance global.
static HINSTANCE g_hInstance;
HINSTANCE AFXISAPI AfxGetResourceHandle()
{
return g_hInstance;
}
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
LPVOID lpReserved)
{
if (ulReason == DLL_PROCESS_ATTACH)
{
g_hInstance = hInst;
}
return TRUE;
}
仅供参考,我已将 Microsoft Foundation 类 标记为在“常规”选项卡下的共享 DLL 中使用 MFC。请帮忙,TIA。
MFC 6.0
使用 MFC42*.LIB
库文件(奇怪但真实)。因此,您 link 的文件名似乎正确。
如果您在 link 您的项目时收到这些错误消息,我猜您的项目文件有问题,或者 Visual C++ 6
没有正确安装。解决办法不是删除这些库,而是找出 Visual C++ 找不到它们的原因。
您的项目正在 unicode-debug
配置中编译。安装Visual C++
时是否安装了unicode库?也许这是一个 opt-in
安装选项(不确定)。您可以使用其他配置(例如 release-unicode)构建您的项目吗?还是调试?
可以帮助您的是创建一个新的空 Visual C++/MFC 项目(File/New Project/C++/MFC/MFC Application)
,这样将得到一个有效的 MFC 项目配置。请务必选择 Unicode 配置,因为这是您要使用的配置。
我下载了一个最初用MFC 4.1开发的项目。我正在尝试在 MFC 6.0 中构建该项目。当我使用 Open WorkSpace
打开它并构建它时,出现以下错误。
Link : fatal error LNK1104: cannot open file "mfc42ud.lib"
在 Internet 上,我找到了解决此错误的解决方案,方法是从项目设置中忽略此库。我这样做了,然后 mfcs42ud.lib
文件出现了类似行的另一个错误。我也修好了。
当我将两个 .lib 文件添加到忽略列表并构建它时,我收到如下所示的 901 错误....
--------------------Configuration: doodads - Win32 Unicode Debug-------------------- Linking... doodads.obj :
error LNK2001: unresolved external symbol __afxForceEXCLUDE ADDRESS.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE expose.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE progress.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE MaskDlg.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE SETKEY.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE SPINNER.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE stats.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE ANIME.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE STDAFX.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE MAINFRM.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE DODADDOC.OBJ : error LNK2001: unresolved external symbol __afxForceEXCLUDE DoDadvw.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE doodads.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX ADDRESS.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX expose.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX progress.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX MaskDlg.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX SETKEY.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX SPINNER.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX stats.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX ANIME.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX STDAFX.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX MAINFRM.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX DODADDOC.OBJ : error LNK2001: unresolved external symbol __afxForceSTDAFX DoDadvw.obj : error LNK2001: unresolved external symbol __afxForceSTDAFX
这是供您参考的代码文件。
Add.h
// ADD.H - Header file for your Internet Server
// add Extension
#include "resource.h"
class CAddExtension : public CHttpServer
{
public:
CAddExtension();
~CAddExtension();
// Overrides
// ClassWizard generated virtual function overrides
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//{{AFX_VIRTUAL(CAddExtension)
public:
virtual BOOL GetExtensionVersion(HSE_VERSION_INFO* pVer);
//}}AFX_VIRTUAL
// TODO: Add handlers for your commands here.
// For example:
void Default(CHttpServerContext* pCtxt,
LPCTSTR pstrOp1, LPCTSTR pstrOp2);
DECLARE_PARSE_MAP()
//{{AFX_MSG(CAddExtension)
//}}AFX_MSG
};
Add.cpp
// ADD.CPP - Implementation file for your Internet Server
// add Extension
#include "stdafx.h"
#include "add.h"
#include <stdio.h>
///////////////////////////////////////////////////////////////////////
// command-parsing map
BEGIN_PARSE_MAP(CAddExtension, CHttpServer)
// TODO: insert your ON_PARSE_COMMAND() and
// ON_PARSE_COMMAND_PARAMS() here to hook up your commands.
// For example:
ON_PARSE_COMMAND(Default, CAddExtension, ITS_PSTR ITS_PSTR)
ON_PARSE_COMMAND_PARAMS("opone=~ optwo=~")
DEFAULT_PARSE_COMMAND(Default, CAddExtension)
END_PARSE_MAP(CAddExtension)
///////////////////////////////////////////////////////////////////////
// The one and only CAddExtension object
CAddExtension theExtension;
///////////////////////////////////////////////////////////////////////
// CAddExtension implementation
CAddExtension::CAddExtension()
{
}
CAddExtension::~CAddExtension()
{
}
BOOL CAddExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
// Call default implementation for initialization
CHttpServer::GetExtensionVersion(pVer);
// Load description string
TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
_tcscpy(pVer->lpszExtensionDesc, sz);
return TRUE;
}
///////////////////////////////////////////////////////////////////////
// CAddExtension command handlers
void CAddExtension::Default(CHttpServerContext* pCtxt,
LPCTSTR pstrOp1, LPCTSTR pstrOp2)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
int nOp1;
int nOp2;
if (*pstrOp1 != '~' && *pstrOp2 != '~')
{
nOp1 = atoi(pstrOp1);
nOp2 = atoi(pstrOp2);
char sz[1024];
sprintf(sz, "The result is: %d\n", nOp1 + nOp2);
*pCtxt << sz;
}
else
{
*pCtxt << "<FORM ACTION=\"http://mooseboy/add.dll\" METHOD=\"GET\">";
*pCtxt << "Enter the first number: <INPUT TYPE=\"text\" NAME=\"opone\" VALUE=\"0\" SIZE=10><p>";
*pCtxt << "Enter the second number: <INPUT TYPE=\"text\" NAME=\"optwo\" VALUE=\"0\" SIZE=10><p>";
*pCtxt << "<p> <INPUT TYPE = \"SUBMIT\" VALUE=\"Add it up\">";
*pCtxt << "</FORM>";
}
EndContent(pCtxt);
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CAddExtension, CHttpServer)
//{{AFX_MSG_MAP(CAddExtension)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
///////////////////////////////////////////////////////////////////////
// If your extension will not use MFC, you'll need this code to make
// sure the extension objects can find the resource handle for the
// module. If you convert your extension to not be dependent on MFC,
// remove the comments arounn the following AfxGetResourceHandle()
// and DllMain() functions, as well as the g_hInstance global.
static HINSTANCE g_hInstance;
HINSTANCE AFXISAPI AfxGetResourceHandle()
{
return g_hInstance;
}
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
LPVOID lpReserved)
{
if (ulReason == DLL_PROCESS_ATTACH)
{
g_hInstance = hInst;
}
return TRUE;
}
仅供参考,我已将 Microsoft Foundation 类 标记为在“常规”选项卡下的共享 DLL 中使用 MFC。请帮忙,TIA。
MFC 6.0
使用 MFC42*.LIB
库文件(奇怪但真实)。因此,您 link 的文件名似乎正确。
如果您在 link 您的项目时收到这些错误消息,我猜您的项目文件有问题,或者 Visual C++ 6
没有正确安装。解决办法不是删除这些库,而是找出 Visual C++ 找不到它们的原因。
您的项目正在 unicode-debug
配置中编译。安装Visual C++
时是否安装了unicode库?也许这是一个 opt-in
安装选项(不确定)。您可以使用其他配置(例如 release-unicode)构建您的项目吗?还是调试?
可以帮助您的是创建一个新的空 Visual C++/MFC 项目(File/New Project/C++/MFC/MFC Application)
,这样将得到一个有效的 MFC 项目配置。请务必选择 Unicode 配置,因为这是您要使用的配置。