Profilo di 风舞干戚太阳粑粑BlogElenchi Strumenti Guida

Blog


07/06/2006

MS VC6 链接错误处理

在Windows XP下编译的软件,放到Windows 2000上使用时,跳出了"无法找到动态链接库MSVCRTD.dll"的提示,后来还是直接将MSVCRTD.dll从WinXP系统目录下copy过来使用来解决问题的。

不过在解决问题过程中,有其他意外收获,现在记下来,说不定以后可参考一二。

刚开始时,我将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.

呵呵,这个错误真厉害,我用google搜索了一下,发现才3页,而且提出问题后后面基本上没有什么解决方法,其中我还硬着头皮看了俄语的链接,但遗憾的是从字面上看没有解答,而后上了微软网站,看到有提问,但是没有回答的。

后来尝试了很多方法,经过摸索,最后得出解决方法:

在Preprocessor中定义_AFXDLL

如果它提示:fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds

就这样改:

C/C++->Code Generation->Multithread DLL (即实现/MD选项)

Commenti (8)

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

臣云 马ha scritto:
就像(没有名称)所言,等于变成了动态调用MFC。
 
30 Ott.
ha scritto:
在Preprocessor中定义_AFXDLL,就 又变成了动态链接MFC了,并且LINK选项也变为/MD,不知如果静态链接的话(LINK选项将自动为/MT),该怎么做呢,LIBCMT.LIB LIBC.LIB MSVCRT.LIB NAFXCW.LIB这几个文件链接冲突,不知道有没有办法让静态编译通过呢?
13 Nov.
ha scritto:
在Preprocessor中定义_AFXDLL,就 又变成了动态链接MFC了,并且LINK选项也变为/MD,不知如果静态链接的话(LINK选项将自动为/MT),该怎么做呢,LIBCMT.LIB LIBC.LIB MSVCRT.LIB NAFXCW.LIB这几个文件链接冲突,不知道有没有办法让静态编译通过呢?
13 Nov.
Immagine di Anonimo
(没有名称) ha scritto:
在Preprocessor中定义_AFXDLL,就又变成了动态链接MFC了,并且LINK选项也变为/MD,不知如果静态链接的话(LINK选项将自动为/MT),该怎么做呢,LIBCMT.LIB LIBC.LIB MSVCRT.LIB NAFXCW.LIB这几个文件链接冲突,不知道有没有办法让静态编译通过呢?
13 Nov.
风舞干戚ha scritto:
呵呵,不好意思,让你受惊了......太绝了......还以为浏览器出了什么问题吧:)
9 Giu.
飞鸟集ha scritto:
我只是觉得挺好玩  呵呵  刚打开的时候,我以为是自己的电脑出毛病了,显示一片这样的
8 Giu.
风舞干戚ha scritto:
这是工作中的点滴,你不必在意:)
8 Giu.
飞鸟集ha scritto:
又出现了我一百年也看不懂的东西:)
7 Giu.

Riferimenti

L'URL di riferimento per questo intervento è:
http://king-dxs.spaces.live.com/blog/cns!827cef33a5708083!178.trak
Blog che fanno riferimento a questo intervento
  • Nessuno