官网目前的版本要求用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
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.
You will require api_id and api_hash to access the Telegram API servers. To learn how to obtain them click here.
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 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 ..
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
For better debugging you may want to install Qt Visual Studio Tools: