MFC導入OSIP庫出現的問題

在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選項)

 

發佈了49 篇原創文章 · 獲贊 8 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章