Skip to content
TGWAY
Channels & Bots STEP 92 / 99

Build TDLib and Make the First Connection

Build TDLib with the official instructions generator: required tools, a measured Windows x64 JSON build with vcpkg, DLLs to ship and what success looks like.

  • Applies toDevelopers
  • LevelL4
  • Reading time5 min
  • Verified

The short answer

  1. 1The route depends on your language; most languages build tdjson and call its C functions.
  2. 2Our Windows x64 JSON build with vcpkg took about 35 minutes; ship tdjson.dll with three DLLs.
  3. 3The first updates show the version and authorizationStateWaitTdlibParameters.
In this article
  1. Decide first: build it, or use what exists
  2. Tools you need
  3. The Windows build, as we actually ran it
  4. The first connection: what success looks like
  5. FAQ
  6. At a glance

Decide first: build it, or use what exists

TDLib is open-source C++, and normally you build it yourself on your own machine. The route depends on the language you write in.

Your languageUsual route
C++ (a CMake project)Build TDLib and link it as a static or JSON library
Java, C#Build the official bindings along with it
Python, JavaScript, Go and othersBuild the JSON library (tdjson) and call its C functions from your language

The exact commands for each platform and language come from the build instructions generator linked from the official TDLib page (core.telegram.org/tdlib). Pick your operating system and language and it prints commands you can paste. This article covers what to know before and after. Whether you need TDLib at all is in the four Telegram APIs.

Tools you need

ToolRequirement (official instructions)
C++ compilerOne that supports C++17; on Windows, the C++ tools of Visual Studio
CMake3.10 or later
LibrariesOpenSSL, zlib
Toolsgperf
OptionalPHP, only for generating documentation or splitting sources for low-memory machines

On Windows the usual way is to install OpenSSL, zlib and gperf with the vcpkg package manager and point CMake at them. Choosing Windows in the generator turns this into commands.

The Windows build, as we actually ran it

These are the steps the generator gives for Windows, x64 and JSON, exactly as we ran them. The commands are for PowerShell, and vcpkg is pinned to the version the generator specifies.

git clone https://github.com/tdlib/td.git
cd td
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
git checkout <the pinned commit the generator shows>
./bootstrap-vcpkg.bat
./vcpkg.exe install gperf:x64-windows openssl:x64-windows zlib:x64-windows
cd ..
mkdir build
cd build
cmake -A x64 -DCMAKE_INSTALL_PREFIX:PATH=../tdlib -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../vcpkg/scripts/buildsystems/vcpkg.cmake ..
cmake --build . --target install --config Release
StageTime taken (measured)
Cloning TDLib and vcpkg, pinning the version, bootstrappingUnder a minute
Installing gperf, OpenSSL and zlib with vcpkgAbout 9.5 minutes
CMake configurationAbout 11 seconds
Building and installing TDLibAbout 24 minutes

We measured on a virtual PC with Windows 11, 8 CPUs and 12 GB of memory, adding --parallel 4 to the last command to keep memory use down. Times depend on your hardware.

  • On its first run, vcpkg downloads the tools it needs, PowerShell 7 and 7-Zip, by itself.
  • gperf's source comes from the GNU servers, which can time out on some networks; it happened to us once. Download the same file from another GNU mirror into vcpkg's downloads folder and run again. vcpkg checks the content by hash, so a different mirror is safe.
  • When the build finishes, tdlib/bin contains tdjson.dll plus OpenSSL (libcrypto-3-x64.dll, libssl-3-x64.dll) and zlib1.dll. Ship all four files with your program.

The first connection: what success looks like

Load tdjson in your program, create a TDLib client and start the receive loop. If the first updates include the TDLib version (the version option) and the authorization state "waiting for parameters" (authorizationStateWaitTdlibParameters), the connection works. In our test both arrived immediately, without logging in.

Next, send setTdlibParameters with your api_id, api_hash and a data folder, and TDLib moves on to the login steps; see getting an api_id and the user login flow. While developing, turn on use_test_dc to run against the test servers with a test account instead of a real one.

Every available method is listed in TDLib's schema file, td_api.tl; see reading the TL schema and layers.

FAQ

How long does it take to build TDLib on Windows?

In our test on an 8-CPU, 12 GB virtual PC, installing dependencies took about 9.5 minutes and the build about 24 minutes.

Which files do I ship with tdjson on Windows?

tdjson.dll plus libcrypto-3-x64.dll, libssl-3-x64.dll and zlib1.dll from tdlib/bin.

How do I know TDLib connected correctly?

The first updates include the version option and authorizationStateWaitTdlibParameters.

Sources

Summary

At a glance

Build TDLib and Make the First Connection — at a glance illustration
  1. 1Tools

    C++17 compiler, CMake 3.10+, OpenSSL, zlib, gperf.

  2. 2Windows

    vcpkg for dependencies; about 9.5 + 24 minutes measured.

  3. 3First run

    Version option and wait-parameters state; lower logging.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›