最近遇到的编译问题,解决方法也都是在网上找到的,再分享下,希望遇到相同问题的朋友可以很快的解决。
在编译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、 编译IDL 文件时,
产生下列错误:
D:/Work/Math/Calculator.idl(3) : error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode : [ Interface 'ICalculator'
]
D:/Work/Math/Calculator.idl(3) : error MIDL2096 : duplicated attribute : [uuid] [ Interface 'ICalculator'
]
Error executing midl.exe.
解决方法是:
需要在project-》setting里的project options
中将IDL 文件的MIDL/mktyplib203 选项去掉