有两个项目,项目一生成一个LIB文件,项目二调用项目一生成的LIB文件。现在修改了生成LIB的项目一,然后重新编译,将
新生成的LIB库文件,拷到生成的LIB库文件到项目二所在的目录,编译项目二时发现出现一堆错误!不知道到底怎么回事了?希望大虾帮忙解决一下Generating Code...
Linking...
nafxcwd.lib(wincore.obj) : error LNK2005: "public: __thiscall CWnd::CWnd(void)" (??0CWnd@@QAE@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: long __thiscall CWnd::Default(void)" (?Default@CWnd@@IAEJXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: static class CWnd * __stdcall CWnd::FromHandle(struct HWND__ *)" (?FromHandle@CWnd@@SGPAV1@PAUHWND__@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::PreSubclassWindow(void)" (?PreSubclassWindow@CWnd@@UAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::PreCreateWindow(struct tagCREATESTRUCTA &)" (?PreCreateWindow@CWnd@@UAEHAAUtagCREATESTRUCTA@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::Create(char const *,char const *,unsigned long,struct tagRECT const &,class CWnd *,unsigned int,struct CCreateContext *)" (?Create@CWnd@@UAEHPBD0KABUtagRECT@@PAV1@IPAUCC
reateContext@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual __thiscall CWnd::~CWnd(void)" (??1CWnd@@UAE@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: void __thiscall CWnd::OnDestroy(void)" (?OnDestroy@CWnd@@IAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual void __thiscall CWnd::PostNcDestroy(void)" (?PostNcDestroy@CWnd@@MAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::OnFinalRelease(void)" (?OnFinalRelease@CWnd@@UAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::DestroyWindow(void)" (?DestroyWindow@CWnd@@UAEHXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long __thiscall CWnd::DefWindowProcA(unsigned int,unsigned int,long)" (?DefWindowProcA@CWnd@@MAEJIIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long (__stdcall** __thiscall CWnd::GetSuperWndProcAddr(void))(struct HWND__ *,unsigned int,unsigned int,long)" (?GetSuperWndProcAddr@CWnd@@MAEPAP6GJPAUHWND__@@IIJ@ZXZ) already defined in
mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CWnd@@UAEHPAUtagMSG@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::OnToolHitTest(class CPoint,struct tagTOOLINFOA *)const " (?OnToolHitTest@CWnd@@UBEHVCPoint@@PAUtagTOOLINFOA@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: void __thiscall CWnd::GetWindowTextA(class CString &)const " (?GetWindowTextA@CWnd@@QBEXAAVCString@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CMenu::TrackPopupMenu(unsigned int,int,int,class CWnd *,struct tagRECT const *)" (?TrackPopupMenu@CMenu@@QAEHIHHPAVCWnd@@PBUtagRECT@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::WinHelpA(unsigned long,unsigned int)" (?WinHelpA@CWnd@@UAEXKI@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual struct AFX_MSGMAP const * __thiscall CWnd::GetMessageMap(void)const " (?GetMessageMap@CWnd@@MBEPBUAFX_MSGMAP@@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long __thiscall CWnd::WindowProc(unsigned int,unsigned int,long)" (?WindowProc@CWnd@@MAEJIIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnWndMsg(unsigned int,unsigned int,long,long *)" (?OnWndMsg@CWnd@@MAEHIIJPAJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnCommand(unsigned int,long)" (?OnCommand@CWnd@@MAEHIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnNotify(unsigned int,long,long *)" (?OnNotify@CWnd@@MAEHIJPAJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CWnd::MessageBoxA(char const *,char const *,unsigned int)" (?MessageBoxA@CWnd@@QAEHPBD0I@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual class CScrollBar * __thiscall CWnd::GetScrollBarCtrl(int)const " (?GetScrollBarCtrl@CWnd@@UBEPAVCScrollBar@@H@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CWnd::GetScrollPos(int)const " (?GetScrollPos@CWnd@@QBEHH@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::CalcWindowRect(struct tagRECT *,unsigned int)" (?CalcWindowRect@CWnd@@UAEXPAUtagRECT@@I@Z) already defined in mfc42.lib(MFC42.DLL)
新生成的LIB库文件,拷到生成的LIB库文件到项目二所在的目录,编译项目二时发现出现一堆错误!不知道到底怎么回事了?希望大虾帮忙解决一下Generating Code...
Linking...
nafxcwd.lib(wincore.obj) : error LNK2005: "public: __thiscall CWnd::CWnd(void)" (??0CWnd@@QAE@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: long __thiscall CWnd::Default(void)" (?Default@CWnd@@IAEJXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: static class CWnd * __stdcall CWnd::FromHandle(struct HWND__ *)" (?FromHandle@CWnd@@SGPAV1@PAUHWND__@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::PreSubclassWindow(void)" (?PreSubclassWindow@CWnd@@UAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::PreCreateWindow(struct tagCREATESTRUCTA &)" (?PreCreateWindow@CWnd@@UAEHAAUtagCREATESTRUCTA@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::Create(char const *,char const *,unsigned long,struct tagRECT const &,class CWnd *,unsigned int,struct CCreateContext *)" (?Create@CWnd@@UAEHPBD0KABUtagRECT@@PAV1@IPAUCC
reateContext@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual __thiscall CWnd::~CWnd(void)" (??1CWnd@@UAE@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: void __thiscall CWnd::OnDestroy(void)" (?OnDestroy@CWnd@@IAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual void __thiscall CWnd::PostNcDestroy(void)" (?PostNcDestroy@CWnd@@MAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::OnFinalRelease(void)" (?OnFinalRelease@CWnd@@UAEXXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::DestroyWindow(void)" (?DestroyWindow@CWnd@@UAEHXZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long __thiscall CWnd::DefWindowProcA(unsigned int,unsigned int,long)" (?DefWindowProcA@CWnd@@MAEJIIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long (__stdcall** __thiscall CWnd::GetSuperWndProcAddr(void))(struct HWND__ *,unsigned int,unsigned int,long)" (?GetSuperWndProcAddr@CWnd@@MAEPAP6GJPAUHWND__@@IIJ@ZXZ) already defined in
mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CWnd@@UAEHPAUtagMSG@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual int __thiscall CWnd::OnToolHitTest(class CPoint,struct tagTOOLINFOA *)const " (?OnToolHitTest@CWnd@@UBEHVCPoint@@PAUtagTOOLINFOA@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: void __thiscall CWnd::GetWindowTextA(class CString &)const " (?GetWindowTextA@CWnd@@QBEXAAVCString@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CMenu::TrackPopupMenu(unsigned int,int,int,class CWnd *,struct tagRECT const *)" (?TrackPopupMenu@CMenu@@QAEHIHHPAVCWnd@@PBUtagRECT@@@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::WinHelpA(unsigned long,unsigned int)" (?WinHelpA@CWnd@@UAEXKI@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual struct AFX_MSGMAP const * __thiscall CWnd::GetMessageMap(void)const " (?GetMessageMap@CWnd@@MBEPBUAFX_MSGMAP@@XZ) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual long __thiscall CWnd::WindowProc(unsigned int,unsigned int,long)" (?WindowProc@CWnd@@MAEJIIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnWndMsg(unsigned int,unsigned int,long,long *)" (?OnWndMsg@CWnd@@MAEHIIJPAJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnCommand(unsigned int,long)" (?OnCommand@CWnd@@MAEHIJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "protected: virtual int __thiscall CWnd::OnNotify(unsigned int,long,long *)" (?OnNotify@CWnd@@MAEHIJPAJ@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CWnd::MessageBoxA(char const *,char const *,unsigned int)" (?MessageBoxA@CWnd@@QAEHPBD0I@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual class CScrollBar * __thiscall CWnd::GetScrollBarCtrl(int)const " (?GetScrollBarCtrl@CWnd@@UBEPAVCScrollBar@@H@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: int __thiscall CWnd::GetScrollPos(int)const " (?GetScrollPos@CWnd@@QBEHH@Z) already defined in mfc42.lib(MFC42.DLL)
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::CalcWindowRect(struct tagRECT *,unsigned int)" (?CalcWindowRect@CWnd@@UAEXPAUtagRECT@@I@Z) already defined in mfc42.lib(MFC42.DLL)
解决方案 »
- 在大巴上公司的笔记本被偷了
- 如何在初始化MONTH CANLENDAR时让其特定的几天被红圈圈住?
- 子窗口的标题
- 如何解决CFile::Write ()中第一个参数与CString类型的转换问题
- 谁能够用socket把本地的一个文件目录完整的拷到另一台计算机
- 在程序中隐式加载DLL,而这个DLL里有一个用CoCreateInstance创建的COM对象指针...
- 如何在对话框程序中处理字符消息?????????/
- 关于控件的问题
- 我用ATL做了个simple object,怎么调试?
- 有关OLE的问题
- 明天过生日,今天散分了!!!!!!!!!
- 如何用DrawText输出几行文字,让其中某一行用别颜色
Article last modified on 2002-3-2
------------------------------------------------------------
The information in this article applies to:
- Microsoft ATL 2.X
------------------------------------------------------------
现象:
当你编译一个ATL工程的Release版时,你得到了下面这个链接错误:
LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
如下图所示:
而Debug版本的编连却顺利通过。
原因与解决方法:
出错原因:
如果你在工程中使用了CRT函数,而这些函数又需要CRT启动代码,就会出现这种链接错误。默认情况下,Release配置的Preprocessor definitions中定义了_ATL_MIN_CRT,它将CRT启动代码从你的EXE或DLL剔出去了。
背景知识:
ATL支持把一个服务器编连优化成最小尺寸或者依赖性最小。我们可以定义三个预处理器符号来影响服务器的优化。
_ATL_MIN_CRT 服务器不链接标准的C/C++运行库
_ATL_DLL 服务器动态链接工具函数库atl.dll
_ATL_STATIC_REGISTRY 服务器静态链接对组件注册的支持
如果定义了预处理器符号_ATL_MIN_CRT,那么我们的服务器不链接C/C++运行库,并且ATL提供了函数malloc、realloc、new和delete的一个实现。当定义了这个符号时,我们不能调用任何其他的C/C++运行库的函数。否则,就会受到这样的待遇:
LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
ATL向导生成的ATL工程为所有的Release版本的编连定义了_ATL_MIN_CRT,但是没有为Debug版本定义这个符号。
Debug配置没有定义这三个符号中的任何一个。
RelMinSize配置定义了_ATL_MIN_CRT和_ATL_DLL。
RelMinDependency配置定义了_ATL_MIN_CRT和_ATL_STATIC_REGISTRY。
2:
C Run-Time Library (without iostream)
Characteristics
Option
Defined
LIBC.LIB
a statically linked library for single-threaded programs
(Single threaded, static link) /ML
LIBCMT.LIB
a statically linked library that supports multithreaded programs
(Multithreaded, static link)
/MT
_MT
MSVCRT.LIB
Multithreaded, dynamic link (import library for MSVCRT.DLL)
/MD
_MT, _DLL
解决方法:
下面方法中的任何一个都可以纠正这个错误:
Ø 去除_ATL_MIN_CRT这个预处理符号;
Ø 打开stdafx.cpp,注释掉#include <atlimpl.cpp>这句话,然后编译,即可;
Ø 在工程的配置对话框的Link页面上,"ignore libraries"编辑框中输入Libcmt.lib,然后编译,如下图所示:
你将会得到几个“unresolved external”的错误,如下所示。
这个列表就是你用到的CRT的函数。
Look for things that you think may be pulling in the startup code and remove them if you can.Instead, use their Win32 equivalents. For example, use lstrcmp() instead of strcmp(). Known functions that require CRT startup code are some of the string and floating point functions.
其他:
我的VC IDE是6.0版本和SP5,如果用ATL COM AppWizard创建Service (EXE)工程。在这种情况下,它的RelMinDependency版本的配置中就没有定义_ATL_MIN_CRT符号!这和微软声称的“Service EXE Created with ATL COM AppWizard Doesn't Build in Release Mode”不一样,可能这是一个已经被FIX了的Bug。
把共有的lib去掉 只引用一次就OK