LNK2005 錯誤
最近在編譯 Filezilla 時,在 Link 階段發生下面的錯誤:
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrt.lib(MSVCRT.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _free already defined in msvcrt.lib(MSVCRT.dll)
在網路上找解答,所得到的答案有:
1.
/MD -> MSVCRT.LIB -> Multithread DLL的Release版本
/MTd -> LIBCMTD.LIB -> Multithread Static的Debug版本
是 debug 和 release 的程式庫在鏈結(Link)時混用了。
2.
Make sure that you have the same code generation options for all
projects. Looking at this it looks like you are linking to the static
single threaded C RTL (MSVCRT.LIB) and the Multithreaded Debug C RTL
(libcmtd.lib). That's off the top of my head though, point being that
those are two separate instances of the RTL and will result in linker
collisions.
原先一直以為是 Filezilla 專案的設定有誤所致,但是裡面只有兩個專案,且是獨立的 exe。後來發現 Filezilla 有使用到 zlib 的 library,所以就再用該專案所附的 VC project 將它編譯一次,當然設定內容要和 Filezilla 一致。然後再將產生的檔提供給 Filezilla 編譯使用,問題就解決了。常常太依賴 IDE 的工具而忘了一些基本的東西,看來要好研究一下聯結器都做了些什麼?
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrt.lib(MSVCRT.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _free already defined in msvcrt.lib(MSVCRT.dll)
在網路上找解答,所得到的答案有:
1.
/MD -> MSVCRT.LIB -> Multithread DLL的Release版本
/MTd -> LIBCMTD.LIB -> Multithread Static的Debug版本
是 debug 和 release 的程式庫在鏈結(Link)時混用了。
2.
Make sure that you have the same code generation options for all
projects. Looking at this it looks like you are linking to the static
single threaded C RTL (MSVCRT.LIB) and the Multithreaded Debug C RTL
(libcmtd.lib). That's off the top of my head though, point being that
those are two separate instances of the RTL and will result in linker
collisions.
原先一直以為是 Filezilla 專案的設定有誤所致,但是裡面只有兩個專案,且是獨立的 exe。後來發現 Filezilla 有使用到 zlib 的 library,所以就再用該專案所附的 VC project 將它編譯一次,當然設定內容要和 Filezilla 一致。然後再將產生的檔提供給 Filezilla 編譯使用,問題就解決了。常常太依賴 IDE 的工具而忘了一些基本的東西,看來要好研究一下聯結器都做了些什麼?