編譯 eMule 專案
今天想藉由 eMule 專案來學習一些 Socket 連線的技巧,但是一開始編譯時就出現了 169 errors。開始進入 Debug 的步驟:
1.首先看到 MSVCRTD.lib(MSVCR71D.dll) : error LNK2005: _memmove already defined in libcmtd.lib(memmove.obj),於是就到 eMule Property Pages 中的 Linker - Input - Ignore Specific Library 中加入 libcmtd.lib。再重新 Compile 後,剩下 146 errors。
2.接著看到 WebServer.obj : error LNK2001: unresolved external symbol _crc32,但是明明zlib 專案中就有該程式,所以朝設定值錯誤的方向努力。在 zconf.h 中看到有兩種 Preprocessor Definitions - ZLIB_WINAPI 與 ZLIB_DLL,所以就將原來的 ZLIB_WINAPI 改為 ZLIB_DLL。再重新 Compile 後,剩下 106 errors。
3.接著看到 SendMail.obj : error LNK2019: unresolved external symbol __imp__CertNameToStrW@20 referenced in function "struct _CERT_CONTEXT const * __cdecl GetCertificate(void *,unsigned long,wchar_t const *)" (?GetCertificate@@YAPBU_CERT_CONTEXT@@PAXKPB_W@Z),透過 Google 查詢 CertNameToStr 的結果,發現是 Wincrypt.h Crypt32.lib 中的函式,所以到 eMule Property Pages 中的 Linker - Input - Additional Dependencies 中加入 crypt32.lib。再重新 Compile 後,剩下 98 errors。
4.接著看到AddSourceDlg.obj : error LNK2019: unresolved external symbol "protected: void __thiscall CResizableDialog::EnableSaveRestore(wchar_t const *,int)" (?EnableSaveRestore@CResizableDialog@@IAEXPB_WH@Z) referenced in function "protected: virtual int __thiscall CAddSourceDlg::OnInitDialog(void)" (?OnInitDialog@CAddSourceDlg@@MAEHXZ),因為有用到 wchar_t,而在 eMule 與 ResizableLib 專案中的設定不同,所以到 ResizableLib Property Pages 中的 C/C++ - Language - Treat wchar_t as Built-in type 中選擇 Yes (/Zc:wchar_t)。再重新 Compile 後,剩下 84 errors。
5.接著看到 msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: class std::basic_istream > & __thiscall std::basic_istream >::seekg(long,int)" (?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@JH@Z) already defined in id3libD.lib(tag_parse.obj),就想會不會是因為 id3libD.lib 因為設定的不同而有 include 入一些相同的 library。所以到 id3lib Property Pages 中的 General - Use of MFC 選擇 Use MFC in a Shared DLL。再重新 Compile 後,剩下 28 errors。
6.接著看到 msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in ClientCredits.obj,就想會不會是因為 eMule 因為設定的不同而有 include 入一些相同的 library。所以到 eMule Property Pages 中的 General - Use of MFC 選擇 Use MFC in a Shared DLL。再重新 Compile 後,剩下 23 errors。
7.接著看到 HttpDownloadDlg.obj : error LNK2019: unresolved external symbol __imp__InternetErrorDlg@20 referenced in function "public: void __thiscall CHttpDownloadDlg::DownloadThread(void)" (?DownloadThread@CHttpDownloadDlg@@QAEXXZ)
,就想應該是沒有include 相關的 library。將 Wininet.lib 加入 Linker - Input - Additional Dependencies 後再重新 Compile 後,剩下 7 errors。
8.接著看到 ComboBoxEx2.obj : error LNK2001: unresolved external symbol ___ascii_stricmp,透過 Google 找不到相關的文章,後來改用 www.alltheweb.com 來找,發現在Microsoft Visual Studio .NET 2003\Vc7\crt\src\stricmp.c 可以找到該函式的原始碼。將該程式碼放入 eMule 的專案中,並將 C/C++ - Precompiled Header - Create/User Precompiled Header 的值設為 Not Using Precompiled Headers,再重新 Compile 後,成功了。
1.首先看到 MSVCRTD.lib(MSVCR71D.dll) : error LNK2005: _memmove already defined in libcmtd.lib(memmove.obj),於是就到 eMule Property Pages 中的 Linker - Input - Ignore Specific Library 中加入 libcmtd.lib。再重新 Compile 後,剩下 146 errors。
2.接著看到 WebServer.obj : error LNK2001: unresolved external symbol _crc32,但是明明zlib 專案中就有該程式,所以朝設定值錯誤的方向努力。在 zconf.h 中看到有兩種 Preprocessor Definitions - ZLIB_WINAPI 與 ZLIB_DLL,所以就將原來的 ZLIB_WINAPI 改為 ZLIB_DLL。再重新 Compile 後,剩下 106 errors。
3.接著看到 SendMail.obj : error LNK2019: unresolved external symbol __imp__CertNameToStrW@20 referenced in function "struct _CERT_CONTEXT const * __cdecl GetCertificate(void *,unsigned long,wchar_t const *)" (?GetCertificate@@YAPBU_CERT_CONTEXT@@PAXKPB_W@Z),透過 Google 查詢 CertNameToStr 的結果,發現是 Wincrypt.h Crypt32.lib 中的函式,所以到 eMule Property Pages 中的 Linker - Input - Additional Dependencies 中加入 crypt32.lib。再重新 Compile 後,剩下 98 errors。
4.接著看到AddSourceDlg.obj : error LNK2019: unresolved external symbol "protected: void __thiscall CResizableDialog::EnableSaveRestore(wchar_t const *,int)" (?EnableSaveRestore@CResizableDialog@@IAEXPB_WH@Z) referenced in function "protected: virtual int __thiscall CAddSourceDlg::OnInitDialog(void)" (?OnInitDialog@CAddSourceDlg@@MAEHXZ),因為有用到 wchar_t,而在 eMule 與 ResizableLib 專案中的設定不同,所以到 ResizableLib Property Pages 中的 C/C++ - Language - Treat wchar_t as Built-in type 中選擇 Yes (/Zc:wchar_t)。再重新 Compile 後,剩下 84 errors。
5.接著看到 msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: class std::basic_istream > & __thiscall std::basic_istream >::seekg(long,int)" (?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@JH@Z) already defined in id3libD.lib(tag_parse.obj),就想會不會是因為 id3libD.lib 因為設定的不同而有 include 入一些相同的 library。所以到 id3lib Property Pages 中的 General - Use of MFC 選擇 Use MFC in a Shared DLL。再重新 Compile 後,剩下 28 errors。
6.接著看到 msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in ClientCredits.obj,就想會不會是因為 eMule 因為設定的不同而有 include 入一些相同的 library。所以到 eMule Property Pages 中的 General - Use of MFC 選擇 Use MFC in a Shared DLL。再重新 Compile 後,剩下 23 errors。
7.接著看到 HttpDownloadDlg.obj : error LNK2019: unresolved external symbol __imp__InternetErrorDlg@20 referenced in function "public: void __thiscall CHttpDownloadDlg::DownloadThread(void)" (?DownloadThread@CHttpDownloadDlg@@QAEXXZ)
,就想應該是沒有include 相關的 library。將 Wininet.lib 加入 Linker - Input - Additional Dependencies 後再重新 Compile 後,剩下 7 errors。
8.接著看到 ComboBoxEx2.obj : error LNK2001: unresolved external symbol ___ascii_stricmp,透過 Google 找不到相關的文章,後來改用 www.alltheweb.com 來找,發現在Microsoft Visual Studio .NET 2003\Vc7\crt\src\stricmp.c 可以找到該函式的原始碼。將該程式碼放入 eMule 的專案中,並將 C/C++ - Precompiled Header - Create/User Precompiled Header 的值設為 Not Using Precompiled Headers,再重新 Compile 後,成功了。