几何尺寸与公差论坛

 找回密码
 注册
查看: 2651|回复: 5

【转帖】bug分析

[复制链接]
发表于 2009-3-22 22:51:42 | 显示全部楼层 |阅读模式
VS2005环境ATL工程报错:error C2065: “_Module”: 未声明的标识符
写在前面:
       最近在接触office编程,使用vc6.0环境Debug能编译通过,但是ReleaseUMinDependenc编译就报错libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _这个问题还没有解决。希望通过CSDN有高手指点,日后再总结6.0环境这个问题。高手门都建议学习ATL COM最好使用VS2005。折腾半天还是遇见这个错误,这个错误又折腾半天!通过Google有问题你就个google)找到CSDN有朋友遇见同样的问题!他的描述如下也是我要表达的):
VC6.0中用ATL生成的全局变量_Module,  
  CComModule  _Module;  
  可以调用_Module.GetResourceInstance();  
   
  用VS2005生成时为_AtlModule,  
  COutLookAddinModule  _AtlModule  
  不能调用GetResourceInstance();怎么办?
在所有回复中没有找到答案!但是通过QQ技术群平台和Google还有百度找到一些方向!
1、VS2005的wizard生成ATL后,发现VS2005会用子类模板化的_AtlModule代替原来VC6.0的_Module
2、VS2005中 ATL 7.0取代了vc6.0中的 ATL 3.0。
3、MSDN英文中有提到CAtlBaseModule   Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.
也就是说要使用GetResourceInstance();  必须派生于CAtlBaseModule 。结果自作聪明到处定义CAtlBaseModule  _Module。结果有不少新的错误!还好我在CSDN发帖有问直接告诉我了!直接使用_AtlBaseModule,微软已经为我们定义好了!在atlcore.h定义了extern CAtlBaseModule _AtlBaseModule;
示例如下:


// 设置位图按钮风格,位图为x32大小,将其放入剪切板中用PasteFace()贴在指定按钮上
        HBITMAP hBmp =(HBITMAP):oadImage(_AtlBaseModule.GetResourceInstance(),
            MAKEINTRESOURCE(IDB_BITMAP),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);

附一:
Earlier versions of ATL used CComModule. In ATL 7.0, CComModule functionality is replaced by several classes:

CAtlBaseModule   Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.

CAtlComModule   Contains information required by the COM classes in ATL.

CAtlWinModule   Contains information required by the windowing classes in ATL.

CAtlDebugInterfacesModule   Contains support for interface debugging.

CAtlModule   The following CAtlModule-derived classes are customized to contain information required in a particular application type. Most members in these classes can be overridden:

CAtlDllModuleT   Used in DLL applications. Provides code for the standard exports.

CAtlExeModuleT   Used in EXE applications. Provides code required in an EXE.

CAtlServiceModuleT   Provides support to create Windows NT and Windows 2000 Services.

CComModule is still available for backward compatibility.
Earlier versions of ATL used CComModule. In ATL 7.0, CComModule functionality is replaced by several classes:

CAtlBaseModule   Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.

CAtlComModule   Contains information required by the COM classes in ATL.

CAtlWinModule   Contains information required by the windowing classes in ATL.

CAtlDebugInterfacesModule   Contains support for interface debugging.

CAtlModule   The following CAtlModule-derived classes are customized to contain information required in a particular application type. Most members in these classes can be overridden:

CAtlDllModuleT   Used in DLL applications. Provides code for the standard exports.

CAtlExeModuleT   Used in EXE applications. Provides code required in an EXE.

CAtlServiceModuleT   Provides support to create Windows NT and Windows 2000 Services.

CComModule is still available for backward compatibility.

附二(写在前面提及的错误,目前还没有找到答案!贴出来希望有高手能指点):
ATL 工程 中ReleaseUMinDependency与 Debug区别是什么?
Debug可以编译通过
ReleaseUMinDependency编译报错
Linking...
  Creating library ReleaseUMinDependency/WordCOM.lib and object ReleaseUMinDependency/WordCOM.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseUMinDependency/WordCOM.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

WordCOM.dll - 2 error(s), 0 warning(s)

注意:
查资料反馈
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
这个错误的修改方法如下:
Windows项目要使用Windows子系统, 而不是Console, 可以这样设置
[Project] --> [Settings] --> 选择"Link"属性页
在Project Options中将/subsystem:console改成/subsystem:windows  

可是我这边这个参数没有错:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"ReleaseUMinDependency/OutLookAddin.pdb" /machine:I386 /def:".\OutLookAddin.def" /out:"ReleaseUMinDependency/OutLookAddin.dll" /implib:"ReleaseUMinDependency/OutLookAddin.lib"
是不是因为我的工程不是 MFC而是ATL,还有其他地方有错误!
第2个错误也没有找到具体的静态库!
希望大家帮帮我!
基本完成office编程(Outlook)的示例程序link
 楼主| 发表于 2009-3-22 22:53:13 | 显示全部楼层

回复: 【转帖】bug分析

error LNK2001: unresolved external symbol _main解决办法
解决外部符号错误:_main,_WinMain@16,__beginthreadex -!t'my`yK  
在创建MFC项目时, 不使用MFC AppWizard向导, 如果没有柚煤孟钅坎问? 就会在编译时产生很多连接错误, 如error LNK2001错误, 典型的错误提示有: m1+4#'  
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main (gd){j  
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 OuR5T>>  
msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16 *_g+&Us1  
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex }t,6 oT  
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex <u%N(=9  
]wpN"w"  
1. Windows子系统设置错误, 提示: )WA5FzPLw  
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main *+oJ(e  
4f{'{1]\  
Windows项目要使用Windows子系统, 而不是Console, 可以这样设置: *^'y#/Dg  
z !DF-%3|  
[Project] --> [Settings] --> 选择"Link"属性页,  Qo!  
在Project Options中将/subsystem:console改成/subsystem:windows   T`H.k"Y{  
Xn?{t*{  
2. Console子系统设置错误, 提示: vwK 7b0M  
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 4Y~E`L0,  
8%P ><"  
控制台项目要使用Console子系统, 而不是Windows, 设置: *Cl5Y':|h  
sipSn4_  
[Project] --> [Settings] --> 选择"Link"属性页, WveN']q\  
在Project Options中将/subsystem:windows改成/subsystem:console [email="BR4C@&#26;Z"]BR4C@Z[/email]  
1 vBkC&  
3. 程序入口设置错误, 提示: dy2$&$=  
msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16 sP.>uExt  
G- (k~1q  
通常, MFC项目的程序入口函数是WinMain, 如果编译项目的Unicode版本, 程序入口必须改为wWinMainCRTStartup, 所以需要重新设置程序入口: r#~P5[aV  
Os hl6 i  
[Project] --> [Settings] --> 选择"Link"属性页, "1zk_#B*  
在Category中选择Output, p HGRL  
再在Entry-point symbol中填入wWinMainCRTStartup, 即可 >IC}SZ  
F)c[@\.dm  
4. 线程运行时库设置错误, 提示: X;t_- f  
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex AmiBqZTp  
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex sz 23_{c?  
oz! {Fd-  
这是因为MFC要使用多线程时库, 需要更改设置: L a-Y,1x](  
uAk>h^pbM  
[Project] --> [Settings] --> 选择"C/C++"属性页, '%ET|1#SO  
在Category中选择Code Generation, ;Y-M)k(  
再在Use run-time library中选择Debug Multithreaded或者multithreaded 0v~5<Y'Z  
咸鱼游侠(75374355) 12:11:11 <mW.@e5_  
其中, W_qa?Jv  
Single-Threaded                单线程静态链接库(release版本) Kh4w Q   
Multithreaded                  多线程静态链接库(release版本) |F]g[En 4  
multithreaded DLL              多线程动态链接库(release版本) s-'qYgA6p  
Debug Single-Threaded          单线程静态链接库(debug版本) _ 7w_./y  
Debug Multithreaded            多线程静态链接库(debug版本) <[ ePw  
Debug Multithreaded DLL        多线程动态链接库(debug版本) H8V/O9|(  
9^x@/  
单线程: 不需要多线程调用时, 多用在DOS环境下 /PJ|d5  
多线程: 可以并发运行 clUdag,C  
静态库: 直接将库与程序Link, 可以脱离MFC库运行 X]pEmHl  
动态库: 需要相应的DLL动态库, 程序才能运行 \n{&_:b+q  
release版本: 正式发布时使用 9J;ZZ/3  
debug版本: 调试阶段使用   k9PoFC#k  


posted on 2008-10-14 22:07 isabc 阅读(362) 评论(2)  编辑 收藏 引用 所属分类: BUG分析


评论
# re: error LNK2001: unresolved external symbol _main解决办法 2008-10-21 21:16 isabc
现象:
当你编译一个ATL工程的Release版时,你得到了下面这个链接错误:

LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main

如下图所示:


而Debug版本的编连却顺利通过。




原因与解决方法:
出错原因:
如果你在工程中使用了CRT函数,而这些函数又需要CRT启动代码,就会出现这种链接错误。默认情况下,Release配置的Preprocessor definitions中定义了_ATL_MIN_CRT,它将CRT启动代码从你的EXE或DLL剔出去了。




背景知识:
1:

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




解决方法:


下面方法中的任何一个都可以纠正这个错误:

&Oslash; 去除_ATL_MIN_CRT这个预处理符号;

&Oslash; 打开stdafx.cpp,注释掉#include <atlimpl.cpp>这句话,然后编译,即可;

&Oslash; 在工程的配置对话框的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。





Written by zhengyun



参考文献:

1. 《INFO: Active Template Library (ATL) 2.0 Readme File [Q165259]》

2. 《INFO: LNK2001 on CRT Symbols in ATL Release Build [Q165076]》
 楼主| 发表于 2009-3-22 22:53:52 | 显示全部楼层

回复: 【转帖】bug分析

结构体对齐问题


//定义的结构体如下:
typedef struct arp_header{
//-----------------------DLC Header----------------------------------------
unsigned char  DesMAC[6]; //目标MAC
unsigned char  SrcMAC[6]; //源MAC            
unsigned short EtherType; //EtherType默认为0x0806是ARP帧的类型值
//-----------------------ARP Frame-----------------------------------------
unsigned short HW_Type; //硬件类型
unsigned short Prot_Type; //上层协议类型
unsigned char  HW_Addr_Len; //MAC地址长度
unsigned char  Prot_Addr_Len; //IP地址类型
unsigned short Opcode; //操作码  0x01表示ARP请求包 0x02表示RARP应答包

unsigned char  Send_MAC_Addr[6]; //发送方MAC
unsigned long  Send_IP_Addr; //发送方IP
unsigned char  Targ_MAC_Addr[6];//接收方MAC
unsigned long  arg_IP_Addr; //接受方IP
unsigned char  padding[18]; //填充数据
}ARPHEADER,*PARPHEADER;

填充:
m_ARPHdr = new ARPHEADER;
//--------------------------------填充ARP头--------------------------------
m_ARPHdr->DesMAC[0] = 0Xff;
m_ARPHdr->DesMAC[1] = 0Xff;
m_ARPHdr->DesMAC[2] = 0Xff;
m_ARPHdr->DesMAC[3] = 0Xff;
m_ARPHdr->DesMAC[4] = 0Xff;
m_ARPHdr->DesMAC[5] = 0Xff;

m_ARPHdr->SrcMAC[0] = 0X00;
m_ARPHdr->SrcMAC[1] = 0X08;
m_ARPHdr->SrcMAC[2] = 0X02;
m_ARPHdr->SrcMAC[3] = 0XDB;
m_ARPHdr->SrcMAC[4] = 0X3B;
m_ARPHdr->SrcMAC[5] = 0X95;

m_ARPHdr->EtherType = 0X0608;
// m_ARPHdr->

m_ARPHdr->HW_Type =0X0100; //硬件类型
m_ARPHdr->rot_Type  = 0X0008; //上层协议类型
m_ARPHdr->HW_Addr_Len = 0X06; //MAC地址长度
m_ARPHdr->rot_Addr_Len =0X04; //IP地址类型
m_ARPHdr->Opcode = 0X0100; //操作码  0x01表示ARP请求包 0x02表示RARP应答包

// m_ARPHdr->Send_MAC_Addr[6]; //发送方MAC
m_ARPHdr->Send_MAC_Addr[0] = 0X00;
m_ARPHdr->Send_MAC_Addr[1] = 0X08;
m_ARPHdr->Send_MAC_Addr[2] = 0X02;
m_ARPHdr->Send_MAC_Addr[3] = 0XDB;
m_ARPHdr->Send_MAC_Addr[4] = 0X3B;
m_ARPHdr->Send_MAC_Addr[5] = 0X95;
m_ARPHdr->Send_IP_Addr =  inet_addr("192.168.11.162"); //发送方IP
// m_ARPHdr->Targ_MAC_Addr[6];//接收方MAC
m_ARPHdr->Targ_MAC_Addr[0] = 0X00;
m_ARPHdr->Targ_MAC_Addr[1] = 0X00;
m_ARPHdr->Targ_MAC_Addr[2] = 0X00;
m_ARPHdr->Targ_MAC_Addr[3] = 0X00;
m_ARPHdr->Targ_MAC_Addr[4] = 0X00;
m_ARPHdr->Targ_MAC_Addr[5] = 0X00;
m_ARPHdr->arg_IP_Addr = inet_addr("192.168.11.154"); //接受方IP
//m_ARPHdr->padding[18] ; //填充数据
memset(&(m_ARPHdr->padding[0]),0,18);

//填充后m_ARPHdr 值如下:
//FF FF FF FF FF FF 00 08 02 DB 3B 95 08 06 00 01 08 00 06 04 00 01 00 08 02 DB 3B 95 C0 A8 0B A2 00 00 00 00 00 00 C0 A8 0B 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
//转换:
u_char* packet = (u_char*)m_ARPHdr;
//转换后packet等于
//FF FF FF FF FF FF 00 08 02 DB 3B 95 08 06 00 01 08 00 06 04 00 01 00 08 02 DB 3B 95 C0 A8 0B A2 00 00 00 00 00 00 CD CD C0 A8 0B 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  

//而且还有一个问题:
int n = sizeof(ARPHEADER);
//等于64;而不是60
为什么C0 A8 0B 02前怎么不是CD CD

posted on 2008-05-25 21:50 isabc 阅读(165) 评论(1)  编辑 收藏 引用 所属分类: BUG分析


评论
# re: 结构体对齐问题 2008-05-25 21:51 isabc
#pragma pack(push)
#pragma pack(1)
typedef struct arp_header{
//-----------------------DLC Header----------------------------------------
unsigned char DesMAC[6]; //目标MAC
unsigned char SrcMAC[6]; //源MAC
unsigned short EtherType; //EtherType默认为0x0806是ARP帧的类型值
//-----------------------ARP Frame-----------------------------------------
unsigned short HW_Type; //硬件类型
unsigned short Prot_Type; //上层协议类型
unsigned char HW_Addr_Len; //MAC地址长度
unsigned char Prot_Addr_Len; //IP地址类型
unsigned short Opcode; //操作码 0x01表示ARP请求包 0x02表示RARP应答包

unsigned char Send_MAC_Addr[6]; //发送方MAC
unsigned long Send_IP_Addr; //发送方IP
unsigned char Targ_MAC_Addr[6];//接收方MAC
unsigned long arg_IP_Addr; //接受方IP
unsigned char padding[18]; //填充数据
}ARPHEADER,*PARPHEADER;
#pragma pack(pop)
 楼主| 发表于 2009-3-22 22:54:40 | 显示全部楼层

回复: 【转帖】bug分析

strcpy()赋值和直接赋值的区别
在路上 11:32:01
struct stUserListNode
{
    char userName[10];
    unsigned int ip;
    unsigned short port;
};
在路上 11:32:59
如何把一个CString赋值给userName
海阔天高 11:33:30
strcpy
在路上 11:43:38
stUserListNode *NodeMsg = new stUserListNode;
strcpy(NodeMsg.userName, strName);
在路上 11:43:46
哥们这样不行
在路上 11:43:58
error C2228: left of '.userName' must have class/struct/union type
鱼绕落水花 11:45:26
lstrcpy(对象.userName,CString变量.GetBuffer(CString变量.Getlength());
海阔天高 11:45:27
strcpy(NodeMsg.userName, strName.GetBuffer());
酱菜Pickle 11:59:21
NodeMsg是指针 请用-> , strName.getbuffer是正解
在路上 12:11:52
strcpy( NodeMsg->userName, strName.GetBuffer(strName.GetLength()))
在路上 12:11:57
OK了
在路上 12:12:30
NodeMsg->userName = strName.GetBuffer(strName.GetLength());

一开始我用这个不行
在路上 12:12:39
两者区别主要是什么
酱菜Pickle 12:58:46
GetBuffer是没有参数的函数
酱菜Pickle 12:59:18
他只是获取CString里面数据区的char* 首地址
酱菜Pickle 13:00:44
所以你 不知直接用NodeMsg->userName拷贝地址,必须申请另外的空间存放,不然你的strName一析构 你的NodeMsg->userName就变成野指针了
酱菜Pickle 13:00:57
所以你 不能直接用NodeMsg->userName拷贝地址,必须申请另外的空间存放,不然你的strName一析构 你的NodeMsg->userName就变成野指针了
在路上 13:20:49
谢谢!
 楼主| 发表于 2009-3-22 22:56:06 | 显示全部楼层

回复: 【转帖】bug分析

sizeof求长度的错误用法。
在路上<isabc@qq.com> 15:57:02
CString strMsg = "ok1ok2ok3ok4";
  char* Buffer = strMsg.GetBuffer(strMsg.GetLength());
  int n = sizeof(Buffer);
在路上<isabc@qq.com> 15:57:31
n怎么等于4
寻路者(158989725) 15:57:51
  int n = sizeof(Buffer);
在路上<isabc@qq.com> 15:57:55
可以这样求吗?
寻路者(158989725) 15:58:13
Buffer是个指针.在32位机器上就是4个字节
Pinck(258360502) 15:58:17
指针.
在路上<isabc@qq.com> 15:58:14
这样啊!

Pinck(258360502) 15:58:25
用strlen
在路上<isabc@qq.com> 15:58:16
谢谢
沧海一粟(17023666) 16:01:49
就是这样的
在路上<isabc@qq.com> 16:03:37
如果是数组就可以对吧
在路上<isabc@qq.com> 16:03:54
char buffer[1024] = {"ok1ok2ok3ok4"};
在路上<isabc@qq.com> 16:04:06
sizeof(buffer)
在路上<isabc@qq.com> 16:04:15
这样可以得到实际长度吧
Pinck(258360502) 16:04:49
不能.
Pinck(258360502) 16:04:59
长度为1024
在路上<isabc@qq.com> 16:05:05
这样啊!!
沧海一粟(17023666) 16:06:23
如果这样就行
sizeof和strlen有区别
如果这样可以的
char buffer[]={"ok1ok2ok3ok4"};
sizeof(buffer);
沧海一粟(17023666) 16:07:00
在网上有好帖子讲这个很详细的。
可以搜索看下

先把错误过程贴出来。有时间再分析下!
发表于 2009-3-25 00:39:52 | 显示全部楼层

回复: 【转帖】bug分析

Robust Spline Filter
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-4-26 05:01 , Processed in 0.045569 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表