在Windows XP下编译的软件,要导入一个osip库,结果出错了,还好最后解决了。记录下来。
#include <osipparser2/osip_message.h>
#include <osipparser2/osip_parser.h>
#include <osipparser2/sdp_message.h>
#pragma comment(lib,"lib/osip_parse2_d.lib")
刚开始时,我将MFC DLL改为静态库链接,编译,出现如下结果:
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _realloc already defined in libcmt.lib(realloc.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _free already defined in libcmt.lib(free.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _malloc already defined in libcmt.lib(malloc.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strchr already defined in libcmt.lib(strchr.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in libcmt.lib(sprintf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _tolower already defined in libcmt.lib(tolower.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _getenv already defined in libcmt.lib(getenv.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _toupper already defined in libcmt.lib(toupper.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __isctype already defined in libcmt.lib(isctype.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _atoi already defined in libcmt.lib(atox.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strstr already defined in libcmt.lib(strstr.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _calloc already defined in libcmt.lib(calloc.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in libcmt.lib(strncpy.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _memmove already defined in libcmt.lib(memmove.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strtoul already defined in libcmt.lib(strtol.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strtol already defined in libcmt.lib(strtol.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in libcmt.lib(fclose.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _ungetc already defined in libcmt.lib(ungetc.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __errno already defined in libcmt.lib(dosmap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sscanf already defined in libcmt.lib(sscanf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _setlocale already defined in libcmt.lib(setlocal.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _printf already defined in libcmt.lib(printf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _localtime already defined in libcmt.lib(localtim.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _time already defined in libcmt.lib(time.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fflush already defined in libcmt.lib(fflush.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: __strdup already defined in libcmt.lib(strdup.obj)
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library
../../Output/Release/FirewallMan.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
相信一个善良的人对上面的错误不会熟视无睹的,我的解决方法当然是对症下药:
Link->Category: Input->Ignore libraries:libcmt
clean后重新编译,还有下面的链接错误:
Linking...
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(dcprev.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
../../Output/Release/FirewallMan.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
后来尝试了很多方法,经过摸索,最后得出解决方法:
在Preprocessor中定义_AFXDLL
如果它提示:fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
就这样改:
C/C++->Code Generation->Multithread DLL (即实现/MD选项)