Telegram的tdesktop之Windows編譯小記

官網目前的版本要求用VS2019編譯windows版本,我也是看了別人流程,之後參考手冊折騰了6天,今天終於把release能運行起來了。做個簡單的記錄,備註如下:

1) 當前版本必須使用VS2019,可以使用免費版本就可以。我開始使用VS2017到了後面的部分報錯。

2)我的開發環境是家裏的windows10x64,需要注意手冊裏要求編譯各種庫爲32位,但是特別需要注意的是:cmake和python一定要用x64安裝版本,不要使用ZIP包,因爲python需要在註冊表裏添加各種信息,如果註冊表裏沒有,後面cmake在加載依賴時候會報錯,並且發現32位版本cmake加載python運行庫有問題。經過了2天的折騰,最後換成了cmake-3.16.4-win64-x64.msi和python-3.8.1-amd64.exe解決了telegram生成解決方案時配置的問題。

3)在openssl編譯,手冊是使用了debug和release分開編譯,這個主要是後面的qt5.12要用,按照手冊裏的方法無法成功配置,總是說無法找到,最後從qt官網找到了5.12.0壓縮包編譯的。這裏簡要說明一下:

3.1)openssl

perl Configure no-shared VC-WIN32 no-asm --prefix=D:\TBuild\Libraries\Qt-5.12.5\OpenSSL
nmake install 
nmake test

大概意思是編譯爲靜態庫,使用32位RELEASE版本,不要彙編(防止以後出現莫名其妙的BUG),安裝後放到指定目錄,一變後續給QT用。INSTALL後會在 D:\TBuild\Libraries\Qt-5.12.5\OpenSSL出現3個目錄:include, lib, bin

3.2)QT

官方給的方法如下:

git clone git://code.qt.io/qt/qt5.git qt_5_12_5
cd qt_5_12_5
perl init-repository --module-subset=qtbase,qtimageformats
git checkout v5.12.5
git submodule update qtbase
git submodule update qtimageformats
cd qtbase
git apply ../../patches/qtbase_5_12_5.diff
cd ..

configure -prefix "%LibrariesPath%\Qt-5.12.5" -debug-and-release -force-debug-info -opensource -confirm-license -static -static-runtime -I "%LibrariesPath%\openssl_1_1_1\include" -no-opengl -openssl-linked OPENSSL_LIBS_DEBUG="%LibrariesPath%\openssl_1_1_1\out32.dbg\libssl.lib %LibrariesPath%\openssl_1_1_1\out32.dbg\libcrypto.lib Ws2_32.lib Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" OPENSSL_LIBS_RELEASE="%LibrariesPath%\openssl_1_1_1\out32\libssl.lib %LibrariesPath%\openssl_1_1_1\out32\libcrypto.lib Ws2_32.lib Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" -mp -nomake examples -nomake tests -platform win32-msvc

但是,我覺得這樣獲得子模塊可能不全造成配置失敗,當時報錯是:ERROR: Feature 'openssl-linked' was enabled, but the pre-condition '!features.securetransport && libs.openssl' failed.

我的方法是去QT官網找一個ZIP,不打補丁,直接編譯,使用的命令參數爲:

configure -confirm-license -opensource -debug-and-release -static -force-debug-info   -nomake examples -nomake tests  -openssl-linked  -platform win32-msvc OPENSSL_PREFIX="D:\TBuild\Libraries\Qt-5.12.5\OpenSSL" OPENSSL_LIBS="libssl.lib libcrypto.lib Ws2_32.lib Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" -prefix "D:\TBuild\Libraries\Qt-5.12.5"


編譯後會在約定目錄生成一大推的靜態庫文件。

之後就準備真正的工作了。

4)tdesktop

api_id: 17349 api_hash: 344583e45741c457fe1862106095a5eb


configure.bat  force  -D TDESKTOP_API_ID=17349 -D TDESKTOP_API_HASH=344583e45741c457fe1862106095a5eb -D DESKTOP_APP_USE_PACKAGED=OFF

我使用了測試版本的ID號,沒有申請自己的。當時因爲CMAKE兼容性問題,一直報告:找到PYTHON可執行程序。其實cmake的support.cmake是默認先去找註冊表,然後通過提示在去找根目錄參數,所以要保證註冊表裏有信息。如果再出錯,那就是兼容性問題。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Python]

[HKEY_CURRENT_USER\Software\Python\PythonCore]
"DisplayName"="Python Software Foundation"
"SupportUrl"="http://www.python.org/"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8]
"DisplayName"="Python 3.8 (64-bit)"
"SupportUrl"="http://www.python.org/"
"Version"="3.8.1"
"SysVersion"="3.8"
"SysArchitecture"="64bit"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\Help]

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\Help\Main Python Documentation]
@="D:\\Python38\\Doc\\python381.chm"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\Idle]
@="D:\\Python38\\Lib\\idlelib\\idle.pyw"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\IdleShortcuts]
@=dword:00000001

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\InstalledFeatures]
"dev"="3.8.1150.0"
"Shortcuts"="3.8.1150.0"
"exe"="3.8.1150.0"
"lib"="3.8.1150.0"
"test"="3.8.1150.0"
"doc_shortcut"="3.8.1150.0"
"doc"="3.8.1150.0"
"tools"="3.8.1150.0"
"tcltk"="3.8.1150.0"
"pip"="3.8.1150.0"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\InstallPath]
@="D:\\Python38\\"
"ExecutablePath"="D:\\Python38\\python.exe"
"WindowedExecutablePath"="D:\\Python38\\pythonw.exe"

[HKEY_CURRENT_USER\Software\Python\PythonCore\3.8\PythonPath]
@="D:\\Python38\\Lib\\;D:\\Python38\\DLLs\\"

如果配置成功了,能看到Telegram.sln,那麼和成功就不遠了,

我的編譯並不順利,首先是報告缺文件,這主要是因爲某些模塊的頭文件是編譯時候自動生成的,要求有順序。

另外,錯誤提示:error C2220: 警告被視爲錯誤 :原因是該文件的代碼頁爲英文,而我們系統中的代碼頁爲中文。

我們需要把警告忽視掉。

 

之後官網的手冊如下:https://github.com/telegramdesktop/tdesktop/blob/dev/docs/building-msvc.md

Build instructions for Visual Studio 2019

Prepare folder

Choose an empty folder for the future build, for example D:\TBuild. It will be named BuildPath in the rest of this document. Create two folders there, BuildPath\ThirdParty and BuildPath\Libraries.

All commands (if not stated otherwise) will be launched from x86 Native Tools Command Prompt for VS 2019.bat (should be in Start Menu > Visual Studio 2019 menu folder). Pay attention not to use any other Command Prompt.

Obtain your API credentials

You will require api_id and api_hash to access the Telegram API servers. To learn how to obtain them click here.

Install third party software

Strawberry

Open x86 Native Tools Command Prompt for VS 2019.bat, go to BuildPath and run

cd ThirdParty
git clone https://github.com/desktop-app/patches.git
cd patches
git checkout 395b620
cd ../
git clone https://chromium.googlesource.com/external/gyp
cd gyp
git checkout 9f2a7bb1
git apply ../patches/gyp.diff
cd ..\..

Add GYP and Ninja to your PATH:

  • Open Control Panel -> System -> Advanced system settings
  • Press Environment Variables...
  • Select Path
  • Press Edit
  • Add BuildPath\ThirdParty\gyp value
  • Add BuildPath\ThirdParty\Ninja value

Clone source code and prepare libraries

Open x86 Native Tools Command Prompt for VS 2019.bat, go to BuildPath and run

SET PATH=%cd%\ThirdParty\Strawberry\perl\bin;%cd%\ThirdParty\Python27;%cd%\ThirdParty\NASM;%cd%\ThirdParty\jom;%cd%\ThirdParty\cmake\bin;%cd%\ThirdParty\yasm;%PATH%

git clone --recursive https://github.com/telegramdesktop/tdesktop.git

mkdir Libraries
cd Libraries

SET LibrariesPath=%cd%

git clone https://github.com/desktop-app/patches.git
cd patches
git checkout 395b620
cd ..
git clone --branch 0.10.0 https://github.com/ericniebler/range-v3 range-v3

git clone https://github.com/desktop-app/lzma.git
cd lzma\C\Util\LzmaLib
msbuild LzmaLib.sln /property:Configuration=Debug
msbuild LzmaLib.sln /property:Configuration=Release
cd ..\..\..\..

git clone https://github.com/openssl/openssl.git openssl_1_1_1
cd openssl_1_1_1
git checkout OpenSSL_1_1_1-stable
perl Configure no-shared debug-VC-WIN32
nmake
mkdir out32.dbg
move libcrypto.lib out32.dbg
move libssl.lib out32.dbg
move ossl_static.pdb out32.dbg\ossl_static
nmake clean
move out32.dbg\ossl_static out32.dbg\ossl_static.pdb
perl Configure no-shared VC-WIN32
nmake
mkdir out32
move libcrypto.lib out32
move libssl.lib out32
move ossl_static.pdb out32
cd ..

git clone https://github.com/desktop-app/zlib.git
cd zlib
cd contrib\vstudio\vc14
msbuild zlibstat.vcxproj /property:Configuration=Debug
msbuild zlibstat.vcxproj /property:Configuration=ReleaseWithoutAsm
cd ..\..\..\..

git clone https://github.com/telegramdesktop/openal-soft.git
cd openal-soft
git checkout fix_capture
cd build
cmake -G "Visual Studio 16 2019" -A Win32 -D LIBTYPE:STRING=STATIC -D FORCE_STATIC_VCRT:STRING=ON ..
msbuild OpenAL.vcxproj /property:Configuration=Debug
msbuild OpenAL.vcxproj /property:Configuration=Release
cd ..\..

git clone https://github.com/google/breakpad
cd breakpad
git checkout a1dbcdcb43
git apply ../../tdesktop/Telegram/Patches/breakpad.diff
cd src
git clone https://github.com/google/googletest testing
cd client\windows
gyp --no-circular-check breakpad_client.gyp --format=ninja
cd ..\..
ninja -C out/Debug common crash_generation_client exception_handler
ninja -C out/Release common crash_generation_client exception_handler
cd tools\windows\dump_syms
gyp dump_syms.gyp
msbuild dump_syms.vcxproj /property:Configuration=Release
cd ..\..\..\..\..

git clone https://github.com/telegramdesktop/opus.git
cd opus
git checkout tdesktop
cd win32\VS2015
msbuild opus.sln /property:Configuration=Debug /property:Platform="Win32"
msbuild opus.sln /property:Configuration=Release /property:Platform="Win32"

cd ..\..\..\..
SET PATH_BACKUP_=%PATH%
SET PATH=%cd%\ThirdParty\msys64\usr\bin;%PATH%
cd Libraries

git clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
cd ffmpeg
git checkout release/3.4

set CHERE_INVOKING=enabled_from_arguments
set MSYS2_PATH_TYPE=inherit
bash --login ../../tdesktop/Telegram/Patches/build_ffmpeg_win.sh

SET PATH=%PATH_BACKUP_%
cd ..

git clone git://code.qt.io/qt/qt5.git qt_5_12_5
cd qt_5_12_5
perl init-repository --module-subset=qtbase,qtimageformats
git checkout v5.12.5
git submodule update qtbase
git submodule update qtimageformats
cd qtbase
git apply ../../patches/qtbase_5_12_5.diff
cd ..

configure -prefix "%LibrariesPath%\Qt-5.12.5" -debug-and-release -force-debug-info -opensource -confirm-license -static -static-runtime -I "%LibrariesPath%\openssl_1_1_1\include" -no-opengl -openssl-linked OPENSSL_LIBS_DEBUG="%LibrariesPath%\openssl_1_1_1\out32.dbg\libssl.lib %LibrariesPath%\openssl_1_1_1\out32.dbg\libcrypto.lib Ws2_32.lib Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" OPENSSL_LIBS_RELEASE="%LibrariesPath%\openssl_1_1_1\out32\libssl.lib %LibrariesPath%\openssl_1_1_1\out32\libcrypto.lib Ws2_32.lib Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" -mp -nomake examples -nomake tests -platform win32-msvc

jom -j4
jom -j4 install
cd ..

Build the project

Go to BuildPath\tdesktop\Telegram and run (using your api_id and api_hash)

configure.bat -D TDESKTOP_API_ID=YOUR_API_ID -D TDESKTOP_API_HASH=YOUR_API_HASH -D DESKTOP_APP_USE_PACKAGED=OFF
  • Open BuildPath\tdesktop\out\Telegram.sln in Visual Studio 2019
  • Select Telegram project and press Build > Build Telegram (Debug and Release configurations)
  • The result Telegram.exe will be located in D:\TBuild\tdesktop\out\Debug (and Release)

Qt Visual Studio Tools

For better debugging you may want to install Qt Visual Studio Tools:

  • Open Tools -> Extensions and Updates...
  • Go to Online tab
  • Search for Qt
  • Install Qt Visual Studio Tools extension
  •  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章