ars3niy / tdlib-purple

libpurple Telegram plugin using tdlib
Other
147 stars 32 forks source link

Linking errors #172

Closed Penaz91 closed 1 year ago

Penaz91 commented 1 year ago

Greetings.

There seems to be an issue when compiling tdlib-purple on my machine. Here's the traceback:

[ 98%] Building CXX object CMakeFiles/telegram-tdlib.dir/secret-chat.cpp.o
[100%] Linking CXX shared library libtelegram-tdlib.so
/usr/bin/ld: /usr/lib/libtdutils.a(crypto.cpp.o): in function `td::pbkdf2_sha256(td::Slice, td::Slice, int, td::MutableSlice)':
(.text._ZN2td13pbkdf2_sha256ENS_5SliceES0_iNS_12MutableSliceE+0x70): undefined reference to `EVP_MD_size'
/usr/bin/ld: /usr/lib/libtdutils.a(crypto.cpp.o): in function `td::pbkdf2_sha512(td::Slice, td::Slice, int, td::MutableSlice)':
(.text._ZN2td13pbkdf2_sha512ENS_5SliceES0_iNS_12MutableSliceE+0x70): undefined reference to `EVP_MD_size'
/usr/bin/ld: /usr/lib/libtdutils.a(crypto.cpp.o): in function `td::rsa_encrypt_pkcs1_oaep(td::Slice, td::Slice)':
(.text._ZN2td22rsa_encrypt_pkcs1_oaepENS_5SliceES0_+0x99): undefined reference to `EVP_PKEY_base_id'
/usr/bin/ld: /usr/lib/libtdutils.a(crypto.cpp.o): in function `td::rsa_decrypt_pkcs1_oaep(td::Slice, td::Slice)':
(.text._ZN2td22rsa_decrypt_pkcs1_oaepENS_5SliceES0_+0x99): undefined reference to `EVP_PKEY_base_id'
/usr/bin/ld: /usr/lib/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_block_sz':
(.text.sqlcipher_openssl_get_block_sz+0x9): undefined reference to `EVP_CIPHER_block_size'
/usr/bin/ld: /usr/lib/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_iv_sz':
(.text.sqlcipher_openssl_get_iv_sz+0x9): undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: /usr/lib/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_key_sz':
(.text.sqlcipher_openssl_get_key_sz+0x9): undefined reference to `EVP_CIPHER_key_length'
/usr/bin/ld: /usr/lib/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_cipher':
(.text.sqlcipher_openssl_get_cipher+0xd): undefined reference to `EVP_CIPHER_nid'
/usr/bin/ld: /usr/lib/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_hmac_sz':
(.text.sqlcipher_openssl_get_hmac_sz+0x2f): undefined reference to `EVP_MD_size'
/usr/bin/ld: (.text.sqlcipher_openssl_get_hmac_sz+0x47): undefined reference to `EVP_MD_size'
/usr/bin/ld: (.text.sqlcipher_openssl_get_hmac_sz+0x5f): undefined reference to `EVP_MD_size'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/telegram-tdlib.dir/build.make:318: libtelegram-tdlib.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:304: CMakeFiles/telegram-tdlib.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Further information

OS: Artix Linux (ArchLinux Derivative) Using aur package telegram-tdlib-purple-git LibPurple/Pidgin version: 2.14.10-1 OpenSSL Version: 3.0.7-2

The version from the telegram-tdlib-purple-minimal-git aur package seems to link fine, but it doesn't show in Pidgin's plugin list.

If any more information is needed, don't hesitate to ask. Thank you for this plugin!

BenWiederhake commented 1 year ago

Hmm, sounds like either you're compiling and linking against different versions of OpenSSL, or perhaps not linking against it at all, for some reason.

Can you try it again with make VERBOSE=1? That should show the exact command used for linking, and should reveal how it thinks it's linking against OpenSSL.

Penaz91 commented 1 year ago

Sure thing, I'm attaching the output of make VERBOSE=1.

build_log.log

BenWiederhake commented 1 year ago

Hmm, it links correctly against ssl and crypto. Looking more closely, all linker errors are in td itself. Is it possible that compiling libtd was faulty somehow?

Let's zoom in on an arbitrary, particular error:

/usr/bin/ld: /usr/lib/libtdutils.a(crypto.cpp.o): in function `td::pbkdf2_sha256(td::Slice, td::Slice, int, td::MutableSlice)':
(.text._ZN2td13pbkdf2_sha256ENS_5SliceES0_iNS_12MutableSliceE+0x70): undefined reference to `EVP_MD_size'

However, there is no EVP_MD_size symbol in any library, and it does not seem to exist in any OpenSSL version. (Not to be confused with EVP_MD_get_size, which does exist.) Instead it should have been a macro: https://github.com/openssl/openssl/blob/33290c534750f031cbf384f0ad8c05555a16f726/include/openssl/evp.h#L546

My best guess is that while compiling tdutils, the compiler somehow silently(?) failed to load the correct headers, and permitted function calls to undefined functions (e.g. EVP_MD_size). This makes sense, since all the other "missing symbols" are also macros of the same header (e.g. EVP_CIPHER_nid and EVP_PKEY_base_id).

Suggestion: Recompile td, read the compilation log, watch out for any weird warnings especially about implicit function definitions. If you somehow had to hand-supply OpenSSL paths to td, that's a likely source for errors.

Penaz91 commented 1 year ago

It seems that recompiling tdlib did the trick!

Now the plugin compiles and links correctly and shows in pidgin's plugin list. I had to log into my accounts again but everything seems to work well!

Thank you very much!