tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
3.17k stars 600 forks source link

how to build cross platform? #180

Closed azkadev closed 3 years ago

azkadev commented 3 years ago

I tried to build for android on linux debian 10 intel 64 bit but there is a failure

I have installed all the required packages but when I type this command a log appears

cmake -DCMAKE_BUILD_TYPE=Release ..

error log

-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
CMake Warning at td/CMakeLists.txt:181 (message):
  Can't find zlib: stop TDLib building

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
ZLIB_LIBRARY
    linked by target "tdutils" in directory /home/azka/telegram-bot-api/td/tdutils

-- Configuring incomplete, errors occurred!
See also "/home/azka/telegram-bot-api/build/CMakeFiles/CMakeOutput.log".
See also "/home/azka/telegram-bot-api/build/CMakeFiles/CMakeError.log".
IRGC commented 3 years ago

Try apt install zlib1g-dev

azkadev commented 3 years ago

now error change

[  0%] Building C object td/sqlite/CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o/home/azka/telegram-bot-api/td/sqlite/sqlite/sqlite3.c:22572:10: fatal error: 'openssl/opensslv.h' file not found
#include <openssl/opensslv.h>
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [td/sqlite/CMakeFiles/tdsqlite.dir/build.make:63: td/sqlite/CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1301: td/sqlite/CMakeFiles/tdsqlite.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
IRGC commented 3 years ago

apt-get install make git zlib1g-dev libssl-dev gperf cmake g++

azkadev commented 3 years ago

apt-get install make git zlib1g-dev libssl-dev gperf cmake g++

I have installed it, but still error

https://github.com/tdlib/telegram-bot-api/issues/180#issuecomment-915443826

please help me i am very newbie in cpp language code

levlam commented 3 years ago

Why do you want to build the Bot API server for Android? How do you plan to run it there?

azkadev commented 3 years ago

Why do you want to build the Bot API server for Android? How do you plan to run it there?

I want to build for android because I want to run my bot 24 hours on android, I have a pc but it will cost money, I will run the bot via termux, termux can run any code language like pc

AYMENJD commented 3 years ago

I don't recommend you to run bot api server in termux. Try to use any other MTPROTO clients or just use the official one api.telegram.org.

levlam commented 3 years ago

Then the simplest way would be to build the server in the Termux itself.

But you will likely have a lot of issues with the local Bot API server on Termux. api.telegram.org cloud server would be much more suitable for a bot running on a phone.

lifegpc commented 3 years ago

I got an another error when I cross compile with NDK The error message:

D:/telegram-bot-api/telegram-bot-api/telegram-bot-api/Client.cpp:462:93: error: no member named 'textEntityTypeMediaTimestamp' in namespace 'td::td_api'; did you mean 'textEntityTypeMentionName'?
      if (entity_type != td_api::textEntityTypeBankCardNumber::ID && entity_type != td_api::textEntityTypeMediaTimestamp::ID) {
                                                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                                            textEntityTypeMentionName
D:/telegram-bot-api/telegram-bot-api/td/td/generate/auto\td/telegram/td_api.h:32144:7: note: 'textEntityTypeMentionName' declared here
class textEntityTypeMentionName final : public TextEntityType {
      ^
D:/telegram-bot-api/telegram-bot-api/telegram-bot-api/Client.cpp:1842:18: error: no member named 'messageChatSetTheme' in namespace 'td::td_api'; did you mean 'messageChatSetTtl'?
    case td_api::messageChatSetTheme::ID:
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~
                 messageChatSetTtl
D:/telegram-bot-api/telegram-bot-api/td/td/generate/auto\td/telegram/td_api.h:19626:7: note: 'messageChatSetTtl' declared here
class messageChatSetTtl final : public MessageContent {
      ^
D:/telegram-bot-api/telegram-bot-api/telegram-bot-api/Client.cpp:1842:10: error: duplicate case value 'ID'
    case td_api::messageChatSetTheme::ID:
         ^
D:/telegram-bot-api/telegram-bot-api/telegram-bot-api/Client.cpp:1827:10: note: previous case defined here
    case td_api::messageChatSetTtl::ID: {
         ^
D:/telegram-bot-api/telegram-bot-api/telegram-bot-api/Client.cpp:8926:18: error: no member named 'messageChatSetTheme' in namespace 'td::td_api'; did you mean 'messageChatSetTtl'?
    case td_api::messageChatSetTheme::ID:
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~
                 messageChatSetTtl
D:/telegram-bot-api/telegram-bot-api/td/td/generate/auto\td/telegram/td_api.h:19626:7: note: 'messageChatSetTtl' declared here
class messageChatSetTtl final : public MessageContent {
      ^
4 errors generated.
ninja: build stopped: subcommand failed.

I already build a zlib and openssl which works on termux. configuration:

cmake -DCMAKE_TOOLCHAIN_FILE=C:/android-ndk-r23/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=21 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=E:/android -DCMAKE_INSTALL_PREFIX=E:/android -DCMAKE_FIND_ROOT_PATH=E:/android ../telegram-bot-api
cmake output ``` -- The CXX compiler identification is Clang 12.0.5 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/android-ndk-r23/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- The C compiler identification is Clang 12.0.5 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/android-ndk-r23/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Could NOT find ccache (this is NOT an error) -- Found OpenSSL: E:/android/lib/libcrypto.so (found version "1.1.1l") -- Found OpenSSL: E:/android/include E:/android/lib/libssl.so;E:/android/lib/libcrypto.so -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - yes -- Found Threads: TRUE -- Performing Test HAVE_STD14 -- Performing Test HAVE_STD14 - Success -- Performing Test HAVE_CXX_FLAG_WALL -- Performing Test HAVE_CXX_FLAG_WALL - Success -- Performing Test HAVE_CXX_FLAG_WEXTRA -- Performing Test HAVE_CXX_FLAG_WEXTRA - Success -- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 -- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Failed -- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH -- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success -- Performing Test HAVE_CXX_FLAG_WCAST_QUAL -- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success -- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE -- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Failed -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Failed -- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO -- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Failed -- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP -- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Failed -- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE -- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Success -- Performing Test HAVE_CXX_FLAG_WVLA -- Performing Test HAVE_CXX_FLAG_WVLA - Success -- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR -- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success -- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER -- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success -- Performing Test HAVE_CXX_FLAG_WCONVERSION -- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success -- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION -- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success -- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC -- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC - Success -- Performing Test HAVE_CXX_FLAG_WDEPRECATED -- Performing Test HAVE_CXX_FLAG_WDEPRECATED - Success -- Performing Test HAVE_CXX_FLAG_WUNUSED_COMMAND_LINE_ARGUMENT -- Performing Test HAVE_CXX_FLAG_WUNUSED_COMMAND_LINE_ARGUMENT - Success -- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS -- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Success -- Performing Test HAVE_CXX_FLAG_WODR -- Performing Test HAVE_CXX_FLAG_WODR - Success -- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING -- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING - Failed -- Found ZLIB: E:/android/lib/libz.so (found version "1.2.11") -- Found ZLIB: E:/android/include E:/android/lib/libz.so -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success -- Performing Test COMPILER_HAS_DEPRECATED_ATTR -- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success -- Configuring done -- Generating done -- Build files have been written to: D:/telegram-bot-api/android ```
lifegpc commented 3 years ago

Looks like just missing some generated files. I remove all CMAKE_CROSSCOMPILING check in cmake files and copy some tools in native build directory to specify location. Now I got a working executable.

levlam commented 3 years ago

@lifegpc The errors mean that you updated Bot API source code, but doesn't regenerated autogenerated source files via native build.

azkadev commented 3 years ago

Screenshot from 2021-10-09 03-52-28 I tried to compile telegram bot api to android but after finishing the file is up to 300 mb is this normal?

lifegpc commented 3 years ago

Screenshot from 2021-10-09 03-52-28 I tried to compile telegram bot api to android but after finishing the file is up to 300 mb is this normal?

You need strip it because it contains debug symbols.

azkadev commented 3 years ago

You need strip it because it contains debug symbols. I tried compiling with this command, but the results are great, is there another trick to make the file

cmake -DCMAKE_TOOLCHAIN_FILE=/home/azkadev/android/ndk/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=29 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/azkadev/android/ndk/build/cmake -DCMAKE_INSTALL_PREFIX=/home/azkadev/android/ndk/build/cmake -DCMAKE_FIND_ROOT_PATH=/home/azkadev/android/ndk/build/cmake ..
lifegpc commented 3 years ago

@azkadev You can find llvm-strip in NDK binary directory. Then call it with:

<path_to_llvm_strip> telegram-bot-api
azkadev commented 3 years ago

@azkadev You can find llvm-strip in NDK binary directory. Then call it with:

<path_to_llvm_strip> telegram-bot-api

Wow you are amazing, thank you very much, now I can build telegram-bot-api for android because of you