2018-12-31 20:04:05 +01:00
# TDLib
2018-01-27 16:57:25 +01:00
TDLib (Telegram Database library) is a cross-platform library for building [Telegram ](https://telegram.org ) clients. It can be easily used from almost any programming language.
2018-12-31 20:04:05 +01:00
2018-01-27 16:57:25 +01:00
## Table of Contents
2018-12-31 20:04:05 +01:00
- [Features ](#features )
2018-01-27 16:57:25 +01:00
- [Examples and documentation ](#usage )
2018-12-31 20:04:05 +01:00
- [Dependencies ](#dependencies )
2018-01-27 16:57:25 +01:00
- [Building ](#building )
2018-12-31 20:04:05 +01:00
- [Installing dependencies ](#installing-dependencies )
2018-01-27 16:57:25 +01:00
- [Using in CMake C++ projects ](#using-cxx )
- [Using in Java projects ](#using-java )
- [Using with other programming languages ](#using-json )
- [License ](#license )
2018-12-31 20:04:05 +01:00
< a name = "features" > < / a >
## Features
`TDLib` has many advantages. Notably `TDLib` is:
* **Cross-platform**: `TDLib` can be used on Android, iOS, Windows, macOS, Linux, Windows Phone, WebAssembly, watchOS, tvOS, Tizen, Cygwin. It should also work on other *nix systems with or without minimal effort.
2018-02-03 22:51:01 +01:00
* **Multilanguage**: `TDLib` can be easily used with any programming language that is able to execute C functions. Additionally it already has native Java (using JNI) bindings and C# (using C++/CLI and C++/CX) bindings.
2018-12-31 20:04:05 +01:00
* **Easy to use**: `TDLib` takes care of all network implementation details, encryption and local data storage.
2018-01-27 16:57:25 +01:00
* **High-performance**: in the [Telegram Bot API ](https://core.telegram.org/bots/api ), each `TDLib` instance handles more than 18000 active bots simultaneously.
2018-12-31 20:04:05 +01:00
* **Well-documented**: all `TDLib` API methods and public interfaces are fully documented.
2018-01-28 11:20:43 +01:00
* **Consistent**: `TDLib` guarantees that all updates are delivered in the right order.
2018-02-03 22:51:01 +01:00
* **Reliable**: `TDLib` remains stable on slow and unreliable Internet connections.
2018-12-31 20:04:05 +01:00
* **Secure**: all local data is encrypted using a user-provided encryption key.
2018-01-28 11:20:43 +01:00
* **Fully-asynchronous**: requests to `TDLib` don't block each other or anything else, responses are sent when they are available.
2018-12-31 20:04:05 +01:00
2018-01-27 16:57:25 +01:00
< a name = "usage" > < / a >
## Examples and documentation
Take a look at our [examples ](https://github.com/tdlib/td/tree/master/example ) and [documentation ](https://core.telegram.org/tdlib/docs/ ).
2018-12-31 20:04:05 +01:00
< a name = "dependencies" > < / a >
2018-01-27 16:57:25 +01:00
## Dependencies
2018-12-31 20:04:05 +01:00
`TDLib` depends on:
2018-01-27 16:57:25 +01:00
* C++14 compatible compiler (Clang 3.4+, GCC 4.9+, MSVC 19.0+ (Visual Studio 2015+), Intel C++ Compiler 17+)
2018-12-31 20:04:05 +01:00
* OpenSSL
* zlib
2018-01-27 16:57:25 +01:00
* gperf (build only)
* CMake (3.0.2+, build only)
* PHP (optional, for docs generation)
* Doxygen (optional, for docs generation)
< a name = "building" > < / a >
## Building
2018-12-31 20:04:05 +01:00
2018-01-27 16:57:25 +01:00
Install all `TDLib` dependencies as described in [Installing dependencies ](#installing-dependencies ).
Then enter directory containing `TDLib` sources and compile them using CMake:
2018-12-31 20:04:05 +01:00
```
mkdir build
cd build
2018-01-27 16:57:25 +01:00
cmake -DCMAKE_BUILD_TYPE=Release ..
2018-12-31 20:04:05 +01:00
cmake --build .
```
< a name = "installing-dependencies" > < / a >
### Installing dependencies
2018-02-14 22:41:26 +01:00
< a name = "macos" > < / a >
#### macOS
2018-02-02 04:25:04 +01:00
* Install the latest Xcode command line tools.
2018-12-31 20:04:05 +01:00
* Install other dependencies, for example, using [Homebrew ](https://brew.sh ):
```
2018-01-03 16:08:53 +01:00
brew install gperf cmake openssl
2018-12-31 20:04:05 +01:00
```
2018-01-27 16:57:25 +01:00
* Build `TDLib` with CMake as explained in [building ](#building ). You may need to manually specify path to the installed OpenSSL to CMake, e.g.,
2018-12-31 20:04:05 +01:00
```
2018-01-27 16:57:25 +01:00
cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ ..
2018-12-31 20:04:05 +01:00
```
2018-02-14 22:41:26 +01:00
< a name = "windows" > < / a >
2018-12-31 20:04:05 +01:00
#### Windows
2018-01-27 16:57:25 +01:00
* Download and install [gperf ](https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/ ). Add the path to gperf to the PATH environment variable.
2018-12-31 20:04:05 +01:00
* Install [vcpkg ](https://github.com/Microsoft/vcpkg#quick-start ).
* Run the following commands:
```
C:\src\vcpkg> .\vcpkg install openssl zlib
```
2018-01-27 16:57:25 +01:00
* Build `TDLib` with CMake as explained in [building ](#building ), but instead of `cmake -DCMAKE_BUILD_TYPE=Release ..` use
2018-03-02 01:13:30 +01:00
```
cmake -DCMAKE_TOOLCHAIN_FILE=C:\src\vcpkg\scripts\buildsystems\vcpkg.cmake ..
```
2018-12-31 20:04:05 +01:00
2018-02-14 22:41:26 +01:00
< a name = "linux" > < / a >
2018-12-31 20:04:05 +01:00
#### Linux
2018-01-27 16:57:25 +01:00
* Install all dependencies using your package manager.
2018-12-31 20:04:05 +01:00
2018-01-27 16:57:25 +01:00
< a name = "using-cxx" > < / a >
## Using in CMake C++ projects
For C++ projects that use CMake, the best approach is to build `TDLib` as part of your project or to use a prebuilt installation.
There are several libraries that you could use in your CMake project:
2018-02-03 22:51:01 +01:00
* Td::TdJson, Td::TdJsonStatic — dynamic and static version of a JSON interface. This has a simple C interface, so it can be easily used with any programming language that is able to execute C functions.
2018-01-27 16:57:25 +01:00
* Td::TdStatic — static library with C++ interface.
* Td::TdCoreStatic — static library with low-level C++ interface intended mostly for internal usage.
For example, part of your CMakeLists.txt may look like this:
```
add_subdirectory(td)
target_link_libraries(YourTarget PRIVATE Td::TdStatic)
```
Or you could install `TDLib` and then reference it in your CMakeLists.txt like this:
```
2018-03-04 22:36:16 +01:00
find_package(Td 1.1.5 REQUIRED)
2018-01-27 16:57:25 +01:00
target_link_libraries(YourTarget PRIVATE Td::TdStatic)
```
See [example/cpp/CMakeLists.txt ](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt ).
< a name = "using-java" > < / a >
## Using in Java projects
TDLib provides native Java interface through JNI.
See [example/java ](https://github.com/tdlib/td/tree/master/example/java ) for example of using TDLib from Java and detailed build and usage instructions.
< a name = "using-json" > < / a >
## Using from other programming languages
`TDLib` provides efficient native C++, Java, and C# (will be released soon) interfaces.
2018-02-03 22:51:01 +01:00
But for most use cases we suggest to use the JSON interface, which can be easily used with any programming language that is able to execute C functions.
See [example/python/tdjson_example.py ](https://github.com/tdlib/td/tree/master/example/python/tdjson_example.py ) for an example of such usage.
2018-01-27 16:57:25 +01:00
< a name = "license" > < / a >
## License
2018-02-03 22:51:01 +01:00
TDLib is licensed under the terms of the Boost Software License. See [LICENSE_1_0.txt ](http://www.boost.org/LICENSE_1_0.txt ) for more information.