備註:編譯環境Microsoft Visual C++ .NET 7.1,編譯版本爲官方eMule v0.49版本,非國內VeryCD版本。
一:下載源代碼和支持庫
1.下載eMule v0.49 源代碼
http://prdownloads.sourceforge.net/emule/eMule0.49c-Sources.zip
2.Crypto v5.1
http://www.cryptopp.com/crypto51.zip
3.zlib v1.2.3
http://www.zlib.net/zlib-1.2.3.tar.gz
4.ResizableLib 1.3 -- A set of MFC classes to easily make resizable windows
http://sourceforge.net/projects/resizablelib/files/ResizableLib/1.3/ResizableLib_1_3.zip/download
5.libpng-1.2.40
http://prdownloads.sourceforge.net/libpng/libpng-1.2.40.tar.gz?download
二:編譯前整理工作
1. 解壓eMule0.49c-Sources.zip到目錄:eMule0.49c-Sources
可以看到eMule主工程目錄在srchybrid文件夾, 另外該文件夾下已經攜帶了三個第三方庫:EditBinX, id3lib, ReplaceVistaIcon和一個空殼庫:zlib(只有工程文件,沒有源文件)
使用VS.NET 2003直接打開srchybrid目錄下的:emule_vc71-all.sln 會提示無法加載另外三個工程:
/crypto51/cryptlib_vc71.vcproj
/ResizableLib/ResizableLib_vc71.vcproj
/libpng/Projects/VisualC71/libpng.vcproj
因此需要把這些第三方工程導入到整個solution中。
2. 解壓crypto51.zip到/eMule0.49c-Sources/crypto51
該工程默認爲VC6打開,複製cryptlib.dsp爲cryptlib_vc71.dsp。使用VS2003打開,講提示是否升級,同意後點擊保存工程會生成:cryptlib_vc71.vcproj
3. 解壓ResizableLib_1_3.zip到/eMule0.49c-Sources/ResizableLib
該工程默認爲VC6打開,使用上述方法生成:ResizableLib_vc71.vcproj
4. 解壓libpng-1.2.40.tar.gz到/eMule0.49c-Sources/libpng
默認即有:/libpng/projects/visualc71/libpng.vcproj
5. 解壓zlib-1.2.3.tar.gz中的文件到已存在的目錄:/eMule0.49c-Sources/zlib
三:開始編譯工作
1. 此時VS2003打開emule_vc71-all.sln將看到比較完整的工程文件夾。根據依賴關係逐個編譯。先編譯依賴庫,再編譯eMule。
2. 編譯crypto
1.Crypto v5.1。對於VC .NET 2003編譯器,我們要對源代碼做以下修改:
在文件integer.cpp中把
AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(size_type n, const void *)
改爲
CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(size_type n, const void *)
在文件pubkey.h中把
template <class PK, class GP>
class DL_KeyImpl : public PK
{
public:
typedef GP GroupParameters;
OID GetAlgorithmID() const {return GetGroupParameters().GetAlgorithmID();}
改爲
template <class PK, class GP, class O = OID>
class DL_KeyImpl : public PK
{
public:
typedef GP GroupParameters;
O GetAlgorithmID() const {return GetGroupParameters().GetAlgorithmID();}
3. 編譯eMule提示無法找到sapi.h,解決線索如下
// NOTE: If you get a compile error due to missing 'sapi.h', look at "emule_site_config.h" for further information.
// 'sapi.h' is not shipped with VS2003.
// Uncomment the following line if you get compile errors due to missing 'sapi.h'
#undef HAVE_SAPI_H
4. 編譯eMule提示無法找到wmsdk.h
// Uncomment the following line if you get compile errors due to missing 'wmsdk.h'
#undef HAVE_WMSDK_H
5. 編譯eMule提示沒有找到wmvcore.lib
從網上下載一個,這個庫是標準DirectShow的組件
6. 編譯eMule提示無法找到:../crypto51/release/cryptlib.lib
需要修改工程設置中的Linker->Input->Additional Dependencies
../crypto51/release/cryptlib.lib 修改爲:
../crypto51/release/cryptlib_vc71.lib
../crypto51/debug/cryptlib.lib 修改爲:
../crypto51/debug/cryptlib_vc71.lib
7. 編譯eMule提示沒有找到ResizableLib.lib.
Solution中ResizableLib Project比較奇怪,編譯環境需要選擇
Lib Release/Debug 而不是:
Unicode Release/Debug
C運行時庫選擇Multi-threaded(/MT)
../ResizableLib/ReleaseUnicode/ResizableLib.lib 修改爲:
../ResizableLib/Release/ResizableLib_vc71.lib
../ResizableLib/DebugUnicode/ResizableLib.lib 修改爲:
../ResizableLib/Debug/ResizableLib_vc71.lib
8. 修改鏈接C的運行時庫
EditBinX: Single-threaded(/ML) à Multi-threaded(/MT)
Ligpng: Multi-threaded DLL(/MD) à Multi-threaded(/MT)
ReplaceVistaIcon: Single-threaded(/ML) à Multi-threaded(/MT)
如果編譯Release版,則所有eMule的支持庫都用/MT編譯。
如果編譯Debug版,則所有eMule的支持庫都用Multi-threaded debug(/MTd)編譯。
如此可以避免很多鏈接衝突問題。