Telegram桌面端(tdesktop)编译方法

Telegram作为一款开源的即时聊天软件,在国外应用的非常广泛。
桌面端采用C++语言编写,界面使用Qt框架进行开发。
作为一款非常成熟的桌面客户端,想必做C++客户端的童鞋也非常想去拜读一下它的源码。
毕竟想成为大神就是要模仿和学习大神的作品呀。

Telegram桌面端截图
不过开源项目的编译确实有时候不那么顺利,我这边也是花了2天时间才完成。

1、首先我们去gayhub哦,不,github上找到tdesktop的仓库。

Telegram Desktop在Github的仓库如下:
https://github.com/telegramdesktop/tdesktop
翻到最后面,有一个编译指南。

这里我们只讨论Windows下的Visual Studio 2017的编译。因为我没有Mac啊。
其实,这个指南已经把大部分步骤讲明白了,可是,还有一些奇怪的地方和注意事项可能没有提到。我们在接下来的过程中,会提醒大家注意的。

2、准备构建项目的文件夹,下载和安装构建工具。

1、首先,你需要选一个好地方,作为Telegram的构建目录,就比如说D盘下的TBuild吧。构建路径:D:\TBuild,我只是说比如,真的不用完全按照这个路径来。我们把这个路径叫做BuildPath吧。后面BuildPath就是指的是D:\TBuild。然后,在这个目录下,创建两个文件夹ThirdParty和Libraries。
ThirdParty文件夹将会放置一些构建工具。
Libraries文件夹将会放置telegram项目所用到的第三方库。

2.0.下载和安装各种构建工具到ThirdParty

2.1.Perl

Download ActivePerl installer from https://www.activestate.com/activeperl/downloads and install to BuildPath\ThirdParty\Perl
去这里下载Perl,并且安装到BuildPath\ThirdParty\Perl。

2.2.NASM

Download NASM installer from http://www.nasm.us and install to BuildPath\ThirdParty\NASM
去这里下载NASM然后安装到BuildPath\ThirdParty\NASM。

2.3.Yasm

Download Yasm executable from http://yasm.tortall.net/Download.html, rename to yasm.exe and put to BuildPath\ThirdParty\yasm
去这里下载Yasm,这个不用安装,直接解压到BuildPath\ThirdParty\yasm目录就行了。最后记得把可执行文件重命名一下,重命名为yasm.exe 。

2.3.MSYS2

Download MSYS2 installer from http://www.msys2.org/ and install to BuildPath\ThirdParty\msys64
去这里下载MSYS2,然后安装到BuildPath\ThirdParty\msys64。这里指南应该是希望我们下载64位的版本的。

2.4.Jom

Download jom archive from http://download.qt.io/official_releases/jom/jom.zip and unpack to BuildPath\ThirdParty\jom
去这里下载Jom,解压到BuildPath\ThirdParty\jom。

2.5.Python2.7

Download Python 2.7 installer from https://www.python.org/downloads/ and install to BuildPath\ThirdParty\Python27
去这里下载Python2.7并安装到BuildPath\ThirdParty\Python27,安装的时候记得勾选添加到PATH。

2.6.CMAKE

Download CMake installer from https://cmake.org/download/ and install to BuildPath\ThirdParty\cmake
去这里下载CMAKE,并安装到BuildPath\ThirdParty\cmake。

2.8.Ninja

Download Ninja executable from https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip and unpack to BuildPath\ThirdParty\Ninja
去这里下载Ninja,并解压到BuildPath\ThirdParty\Ninja。

3.下载源码和准备第三方库

3.0.打开Visual Studio 2017 x86本地命令提示符。

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

指南里面说必须用2017,那这里我们就先用2017吧,我也不知道其他版本行不行。
打开Visual Studio 2017 x86本地命令提示符后切换目录到BuildPath。

3.1.Clone GYP

这里我们还需要一个构建工具,GYP。在命令行中执行。

cd ThirdParty
git clone https://chromium.googlesource.com/external/gyp
cd gyp
git checkout a478c1ab51
cd ..\..

如果你发现gyp始终clone不下来,这时候你可能要科学上网。不过,后面的github上的仓库几乎都可以正常访问,最多有些慢吧。

3.2.设置GYP和Ninja的目录到PATH

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

打开高级系统设置。把BuildPath\ThirdParty\gyp和BuildPath\ThirdParty\Ninja添加到PATH。完成后,可能需要注销或重启一下。
试试看命令提示符里面执行

ninja --version

gyp -h

看看path生效没有,这两个构建工具应该是在后面的Visual Studio 2017编译工程的时候也要用到,所以添加到了系统PATH。
如果你重启了,记得重新打开Visual Studio 2017 x86本地命令提示符,并切换目录到BuildPath。

3.3.把构建工具的目录添加到PATH。

执行以下指令,把其他构建工具添加到PATH。

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

3.4.Clone Telegram源码

执行以下指令,clone telegram源码。

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

这时如果你发现网速慢,不要在github上直接下载源码,再解压。因为它是一个递归clone。--recursive,除了telegram以外,它会clone一些telegram以外的仓库。

3.5.Clone一大堆的第三方库

切换到Libraries目录,下面都是Clone和编译第三方库。按顺序执行就是了,如果你在编译过程中,遇到了问题,请翻到下一节,看一下解决方法。编译的时候请注意以下最后的完成结果,不要报错了还继续步骤,最后可能不成功的。

mkdir Libraries
cd Libraries
git clone https://github.com/Microsoft/Range-V3-VS2015 range-v3git clone https://github.com/telegramdesktop/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
cd openssl
git checkout OpenSSL_1_0_1-stable
perl Configure no-shared --prefix=%cd%\Release --openssldir=%cd%\Release VC-WIN32
ms\do_ms
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
xcopy tmp32\lib.pdb Release\lib\
nmake -f ms\nt.mak clean
perl Configure no-shared --prefix=%cd%\Debug --openssldir=%cd%\Debug debug-VC-WIN32
ms\do_ms
nmake -f ms\nt.mak
nmake -f ms\nt.mak install
xcopy tmp32.dbg\lib.pdb Debug\lib\
cd ..git clone https://github.com/telegramdesktop/zlib.git
cd zlib
git checkout tdesktop
cd contrib\vstudio\vc14
msbuild zlibstat.vcxproj /property:Configuration=Debug
msbuild zlibstat.vcxproj /property:Configuration=ReleaseWithoutAsm
cd ..\..\..\..git clone git://repo.or.cz/openal-soft.git
cd openal-soft
git checkout 18bb46163af
cd build
cmake -G "Visual Studio 15 2017" -D LIBTYPE:STRING=STATIC -D FORCE_STATIC_VCRT:STRING=ON ..
msbuild OpenAL32.vcxproj /property:Configuration=Debug
msbuild OpenAL32.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
set GYP_MSVS_VERSION=2017
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 ..\..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 Librariesgit clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
cd ffmpeg
git checkout release/3.4set CHERE_INVOKING=enabled_from_arguments
set MSYS2_PATH_TYPE=inherit
bash --login ../../tdesktop/Telegram/Patches/build_ffmpeg_win.shSET PATH=%PATH_BACKUP_%
cd ..git clone git://code.qt.io/qt/qt5.git qt5_6_2
cd qt5_6_2
perl init-repository --module-subset=qtbase,qtimageformats
git checkout v5.6.2
cd qtimageformats
git checkout v5.6.2
cd ..\qtbase
git checkout v5.6.2
git apply ../../../tdesktop/Telegram/Patches/qtbase_5_6_2.diff
cd ..configure -debug-and-release -force-debug-info -opensource -confirm-license -static -I "%cd%\..\openssl\Release\include" -no-opengl -openssl-linked OPENSSL_LIBS_DEBUG="%cd%\..\openssl\Debug\lib\ssleay32.lib %cd%\..\openssl\Debug\lib\libeay32.lib" OPENSSL_LIBS_RELEASE="%cd%\..\openssl\Release\lib\ssleay32.lib %cd%\..\openssl\Release\lib\libeay32.lib" -mp -nomake examples -nomake tests -platform win32-msvc2015jom -j4
jom -j4 install
cd ..

3.6.编译时报错的解决方案

1、如果执行msbuild时遇到SDK版本相关的问题时,去那个目录下,用Visual Studio 2017打开sln(Visual Studio解决方案)。把工程的目标SDK重定一下。选一个下拉列表中已安装的SDK,然后点确定,最好是所有的库都用一样的吧。


2、CMAKE OpenAL-Soft的时候报错。

它应该提示了多少行有个东西没法识别。
我这边提示的时942行,-D_WIN32_WINNT=0x0502。
把这个从openal-soft/CMakeLists.txt文件中删除,重新CMAKE一遍。

3、编译Qt,执行configure的时候,如果遇到以下提示。

这确实是一个很奇怪的问题,我后来在telegram的issue上找到了答案。
https://github.com/telegramdesktop/tdesktop/issues/3702

QtBootstrapd.lib(qbytearray.obj) : error LNK2019: 无法解析的外部符号 _z_compress2,该符号在函数 “class QByteArray __cdecl qCompress(unsigned char const *,int,int)” (?qCompress@@ya?AVQByteArray@@PBEHH@Z) 中被引用
QtBootstrapd.lib(qbytearray.obj) : error LNK2019: 无法解析的外部符号 _z_uncompress,该符号在函数 “class QByteArray __cdecl qUncompress(unsigned char const *,int)” (?qUncompress@@ya?AVQByteArray@@pbeh@Z) 中被引用
……\bin\moc.exe : fatal error LNK1120: 2 个无法解析的外部命令.

请按照以下步骤解决。
1、打开文件BuildPath\Libraries\qt5_6_2\qtbase\tools\configure\environment.cpp。
2、找到函数QString Environment::msvcVersion()。
3、把QString version = execute(command, &returnValue);替换成
QString version = “Microsoft (R) C/C++ Optimizing Compiler Version 19.12.25835 for x86”;
4、重新configure。

3.7.生成Visual Studio解决方案

第三方库都编译完成了,这时候,按照如下指令切换到telegram源码工程目录,生成解决方案。

cd ../tdesktop/Telegram
gyp\refresh.bat

执行完之后,你应该可以在BuildPath\tdesktop\Telegram\Telegram.sln看到sln文件,啊,终于出现了!!!有生之年!!!

4.打开解决方案编译Telegram

1、用Visual Studio 2017打开BuildPath\tdesktop\Telegram\Telegram.sln。
2、选择telegram工程,点右键,构建。

这个过程也挺久的。

5.完成

终于看到久违的Telegram,注意,要登录Telegram也要科学上网。

参考资料:
1、Telegram之tdesktop源码编译
2、Telegram编译Qt的问题 issues3702
3、Telegram编译指南

Telegram桌面端(tdesktop)编译方法相关推荐

  1. 使用VS2022编译Telegram桌面端(tdesktop)

    2018年的时候参考Telegram桌面端(tdesktop)编译方法成功编译过tdesktop,后来比较忙,就没管它了 这段时间正好在研究IM,就把当年的Telegram工程找出来,依然能正常编译, ...

  2. 跨桌面端之组件化实践

    本文主要介绍了千牛PC跨端框架中,我们关于组件化部分的思考.方案选择.遇到的一些问题和解法. 此文为本系列文章第三篇, 第一篇:跨全端SDK技术演进 第二篇:跨桌面端之Web容器演进 本文:跨桌面端之 ...

  3. 使用ComposeDesktop开发一款桌面端多功能APK工具

    前言 终于算是忙完了一个阶段!!!从4月份开始,工作内容以及职务上都进行了较大的变动,最直接的就是从海外项目组调到了国内项目组.国内项目组目前有两个应用在同时跑着,而且还有几个马甲包也要维护,不知道大 ...

  4. electron 桌面端业务中的小结(坑)

    文章目录 简介 安装electron依赖 本地数据库选择 indexedDB 封装的库 SQLite Lowdb electron-store electron-json-storage-alt.el ...

  5. Element 2.6.0 发布,基于 Vue 2.0 的桌面端组件库

    开发四年只会写业务代码,分布式高并发都不会还做程序员?   Element 2.6.0 发布了,Element 是一套为开发者.设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库,提供了配套设 ...

  6. 技术干货 | 基于 Qt Quick Plugin 快速构建桌面端跨平台组件

    导读:桌面端的 UI 开发框架对比移动端.Web 端的成熟方案,一直处于不温不火的状态.随着疫情掀起的风波,桌面端在线教育.视频会议等需求不断涌现.本文将围绕 Qt Quick 的优势来介绍如何快速创 ...

  7. arm linux打印机驱动编译方法,嵌入式linux驱动打印机HP系列

    arm linux打印机驱动编译方法和过程记录(2017.03.15): 改动添加概述: 添加foo2zjs工具(用于发送数据到打印机进行打印): 添加gohstscript工具(用于转换文档格式到打 ...

  8. Windows桌面端录屏采集实现

    实时屏幕共享功能,在视频会议.游戏直播.在线教育等场景中已广泛被应用.近日,主打屏幕分享的社交应用「Squad」被Twitter收购,让我们看到了实时屏幕共享融于更多行业,开启丰富玩法的趋势. 作为实 ...

  9. vue2.0桌面端框架_Element-UI组件库(Vue2.0桌面端组件库)V2.9.2 免费版

    Element-UI组件库(Vue2.0桌面端组件库)是一款很优秀好用的为开发者.设计师和产品经理推出的基于Vue 2.0的桌面端组件库软件.小编带来的这款Element-UI组件库功能强大全面,简单 ...

最新文章

  1. 人工智能到底是啥_人工智能的本质究竟是什么?
  2. jquery地址栏链接与a标签链接匹配添加样式!
  3. C语言素数分解prime factoriziation算法(附完整源码)
  4. html美化file按钮,css 美化file按钮
  5. P4159 [SCOI2009] 迷路
  6. 史上最强多线程面试44题和答案:线程锁+线程池+线程同步等
  7. 找不到元数据文件“ .dll”
  8. [BZOJ2006][NOI2010]超级钢琴
  9. OpenCasCade网格的显示
  10. 在minst数据集上定义和训练CNN卷积神经网络,代码+原理+模型更改
  11. 数据仓库与数据挖掘实践期末复习总结
  12. python +appium实现原理_Appium工作原理
  13. 了解卡尔曼滤波器2--最优状态估计
  14. 麦田的守望者背景与分析
  15. 【大战函数——把函数彻底吃透】
  16. 解决video标签在部分安卓默认浏览器上的播放样式问题
  17. 2-6年“iOS开发”,跳槽简历思路(必备)
  18. 关于浏览器核心的一些思考
  19. 光阑,像差和成像光学仪器
  20. Matlab产生正交矩阵

热门文章

  1. find the th smallest
  2. cat 大众点评 mysql_搭建大众点评CAT监控平台
  3. 这个技术的出现,可能会颠覆阿里云、AWS!
  4. 软著申请具体需要哪些步骤呢?
  5. 交换机、路由器、网关的概念和用途
  6. Ubuntu卸载 JAVA
  7. 【毕业设计/Matlab系列】一维加噪信号的小波去噪matlab实现(不采用matlab工具箱)
  8. 修改element内置样式-包含行内样式
  9. 植物叶片——抗氧化物酶
  10. 计算机数控机床用英语怎么说,数控机床专业英语翻译.doc