几个问题及解决方法
2010-06-07 09:02
155 查看
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
p
{mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:宋体;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
在编译VC
工程时出现的编译错误
问题如下:
1、Linking...
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in
LIBCD.lib(fclose.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _free already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _malloc already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in
LIBCD.lib(strncpy.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in
LIBCD.lib(sprintf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __isctype already defined in
LIBCD.lib(isctype.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __close already defined in
LIBCD.lib(close.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __write already defined in
LIBCD.lib(write.obj)
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of
other libs; use /NODEFAULTLIB:library
Debug/module.exe : fatal error LNK1169: one or more multiply defined symbols
found
Error executing link.exe.
原因及解决方法如下:主程序的库与 LIBCD
库链接方式不一致造成的。本例中LIBCD
是用动态链接的
所以可以设置:project->setting-> Generation->Use MFC
in a shared DLL
2、
c:/program files/microsoft visual
studio/vc98/mfc/include/afxv_w32.h(14) : fatal error C1189: #error :
WINDOWS.H already included. MFC apps must not #include <windows.h>
于是, 我在VC6.0
集成环境中的菜单项project
下的setting
中设置使用MFC
例"use mfc in a shared DLL"
即:
project->setting->general->Microsoft Foundation Classed:
选择 Use MFC in a shared DLL"
同时,加入:
#include
<afxwin.h>//
使用MFC
学会两点:
(1)
、在project->setting->general->Microsoft
Foundation Classed:
选择 Use MFC in a shared DLL
(2
)、#include
顺序调换可能会解决问题
3、windows.h和winsock2.h头文件包含顺序
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
大凡在Windows
平台下用C++
做网络开发很多时候都会同时包含这两个头文件,如若顺序不当(windows.h
先于winsock2.h)
就会出现很多莫名其妙的错误。诸如:
警告 4 warning C4005:
“AF_IPX”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 91
警告 5 warning C4005:
“AF_MAX”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 127
警告 6 warning C4005:
“SO_DONTLINGER”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 163
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
只要将二者的包含顺序调换一下问题就会解决,原因参见下面那个链接。另外,上述问题不仅影响直接包含二者的文件,还影响
间接包含的情形。比如,a.h
包含了windows.h
,b.h
包含了winsock2.h
,如果在c.h
当中要引用a.h
和b.h
,那么正确的顺序应当 是b.h
先于a.h
。当然,实践当中有时很难找到究竟是哪两个文件顺序不对了,终极的解决办法是,在当前工程(就是编译不过的这个工程)所有 include
语句最前面加上#include <winsock2.h>
和#include<windows.h>
,世界清静了。
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
在包含了<windows.h>
以及<winsock2.h>
的工程中,
编译有时会出现如
下错误:
error C2011: 'fd_set' : 'struct' type redefinition
error C2011: 'timeval' : 'struct' type redefinition
....
error C2375: 'accept' : redefinition; different
linkage
[
原因分析]
主要原因是因为<windows.h>
中包含了<winsock.h>
头文件,
由于其版
本的不同,导致出现上述的错误。<windows.h>
中相关代码如下:
#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
........
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
.......
#include <commdlg.h>
#endif
#endif
[
解决方案]
由以上代码可以看出如果在没有定义WIN32_LEAN_AND_MEAN
宏的大前
提下windows.h
有可能包含winsock.h
头文件,因此我们得出一个很简单
的解决方法就是在包含<windows.h>
之前定义WIN32_LEAN_AND_MEAN
宏,
如
下所示
:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
p
{mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:宋体;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
在编译VC
工程时出现的编译错误
问题如下:
1、Linking...
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in
LIBCD.lib(fclose.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _free already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _malloc already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in
LIBCD.lib(strncpy.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in
LIBCD.lib(sprintf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __isctype already defined in
LIBCD.lib(isctype.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __close already defined in
LIBCD.lib(close.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __write already defined in
LIBCD.lib(write.obj)
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of
other libs; use /NODEFAULTLIB:library
Debug/module.exe : fatal error LNK1169: one or more multiply defined symbols
found
Error executing link.exe.
原因及解决方法如下:主程序的库与 LIBCD
库链接方式不一致造成的。本例中LIBCD
是用动态链接的
所以可以设置:project->setting-> Generation->Use MFC
in a shared DLL
2、
c:/program files/microsoft visual
studio/vc98/mfc/include/afxv_w32.h(14) : fatal error C1189: #error :
WINDOWS.H already included. MFC apps must not #include <windows.h>
于是, 我在VC6.0
集成环境中的菜单项project
下的setting
中设置使用MFC
例"use mfc in a shared DLL"
即:
project->setting->general->Microsoft Foundation Classed:
选择 Use MFC in a shared DLL"
同时,加入:
#include
<afxwin.h>//
使用MFC
学会两点:
(1)
、在project->setting->general->Microsoft
Foundation Classed:
选择 Use MFC in a shared DLL
(2
)、#include
顺序调换可能会解决问题
3、windows.h和winsock2.h头文件包含顺序
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
大凡在Windows
平台下用C++
做网络开发很多时候都会同时包含这两个头文件,如若顺序不当(windows.h
先于winsock2.h)
就会出现很多莫名其妙的错误。诸如:
警告 4 warning C4005:
“AF_IPX”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 91
警告 5 warning C4005:
“AF_MAX”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 127
警告 6 warning C4005:
“SO_DONTLINGER”:
宏重定义 c:/program
files/microsoft sdks/windows/v6.0a/include/ws2def.h 163
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
只要将二者的包含顺序调换一下问题就会解决,原因参见下面那个链接。另外,上述问题不仅影响直接包含二者的文件,还影响
间接包含的情形。比如,a.h
包含了windows.h
,b.h
包含了winsock2.h
,如果在c.h
当中要引用a.h
和b.h
,那么正确的顺序应当 是b.h
先于a.h
。当然,实践当中有时很难找到究竟是哪两个文件顺序不对了,终极的解决办法是,在当前工程(就是编译不过的这个工程)所有 include
语句最前面加上#include <winsock2.h>
和#include<windows.h>
,世界清静了。
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
在包含了<windows.h>
以及<winsock2.h>
的工程中,
编译有时会出现如
下错误:
error C2011: 'fd_set' : 'struct' type redefinition
error C2011: 'timeval' : 'struct' type redefinition
....
error C2375: 'accept' : redefinition; different
linkage
[
原因分析]
主要原因是因为<windows.h>
中包含了<winsock.h>
头文件,
由于其版
本的不同,导致出现上述的错误。<windows.h>
中相关代码如下:
#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
........
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
.......
#include <commdlg.h>
#endif
#endif
[
解决方案]
由以上代码可以看出如果在没有定义WIN32_LEAN_AND_MEAN
宏的大前
提下windows.h
有可能包含winsock.h
头文件,因此我们得出一个很简单
的解决方法就是在包含<windows.h>
之前定义WIN32_LEAN_AND_MEAN
宏,
如
下所示
:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
相关文章推荐
- MySQL恢复中的几个问题解决方法
- Android常见的几个问题及解决方法
- 今天遇到的几个问题以及解决方法
- 分享一下Mysql常见的几个错误问题及解决方法
- windows下安装openssl时遇到的几个问题和解决方法
- Chrome extension的manifest_version升级过程几个棘手问题的解决方法
- cm13 编译过程中遇到的几个问题及解决方法
- Windows 7 几个小问题的解决方法(二)
- 安装SQL2000时的几个问题和解决方法
- NHibernate 的几个问题解决方法
- 安装Exchange 2013 CU18遇到的几个问题和解决方法
- 关于html+ashx开发中几个问题的解决方法
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
- 几个小方法解决手机烧流量问题
- VC++.NET 2005 几个比较难缠的问题及其解决方法
- jquery 缓存问题的几个解决方法
- 笔记:工作过程中遇到的几个问题和相应的解决方法(ffmpeg, SDL)
- android安装过程中的几个蛋疼问题解决方法
- 关于html+ashx开发中几个问题的解决方法
- Mysql常见的几个错误问题及解决方法: 推荐