tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

Cannot build anymore (undefined reference to `EVP_CIPHER_nid') #2269

Closed matheusfillipe closed 1 year ago

matheusfillipe commented 1 year ago

OS: Archlinux kernel: 6.1.5-arch2-1 SMP PREEMPT_DYNAMIC Thu, 12 Jan 2023 22:42:33 +0000 x86_64 GNU/Linux Tdlib: 1.8.10 from commit: 93c42f6d

Until 1.8.4 the build process would go ok. Now it stops at:

[ 76%] Building CXX object CMakeFiles/tg_cli.dir/td/telegram/cli.cpp.o
[ 76%] Building CXX object CMakeFiles/tg_cli.dir/td/generate/auto/td/telegram/td_api_json.cpp.o
[ 78%] Linking CXX executable tg_cli
/usr/bin/ld: sqlite/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_cipher':
sqlite3.c:(.text.sqlcipher_openssl_get_cipher+0x5): undefined reference to `EVP_CIPHER_nid'
/usr/bin/ld: sqlite/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_key_sz':
sqlite3.c:(.text.sqlcipher_openssl_get_key_sz+0x4): undefined reference to `EVP_CIPHER_key_length'
/usr/bin/ld: sqlite/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_iv_sz':
sqlite3.c:(.text.sqlcipher_openssl_get_iv_sz+0x4): undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: sqlite/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_block_sz':
sqlite3.c:(.text.sqlcipher_openssl_get_block_sz+0x4): undefined reference to `EVP_CIPHER_block_size'
/usr/bin/ld: sqlite/libtdsqlite.a(sqlite3.c.o): in function `sqlcipher_openssl_get_hmac_sz':
sqlite3.c:(.text.sqlcipher_openssl_get_hmac_sz+0x19): undefined reference to `EVP_MD_size'
/usr/bin/ld: sqlite3.c:(.text.sqlcipher_openssl_get_hmac_sz+0x27): undefined reference to `EVP_MD_size'
/usr/bin/ld: sqlite3.c:(.text.sqlcipher_openssl_get_hmac_sz+0x35): undefined reference to `EVP_MD_size'
/usr/bin/ld: tdutils/libtdutils.a(crypto.cpp.o): in function `td::pbkdf2_impl(td::Slice, td::Slice, int, td::MutableSlice, evp_md_st const*)':
crypto.cpp:(.text._ZN2tdL11pbkdf2_implENS_5SliceES0_iNS_12MutableSliceEPK9evp_md_st+0x45): undefined reference to `EVP_MD_size'
/usr/bin/ld: tdutils/libtdutils.a(crypto.cpp.o): in function `td::rsa_encrypt_pkcs1_oaep(td::Slice, td::Slice)':
crypto.cpp:(.text._ZN2td22rsa_encrypt_pkcs1_oaepENS_5SliceES0_+0x78): undefined reference to `EVP_PKEY_base_id'
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/tg_cli.dir/build.make:126: tg_cli] Error 1
make[1]: *** [CMakeFiles/Makefile2:666: CMakeFiles/tg_cli.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
levlam commented 1 year ago

You are building the code with headers from OpenSSL < 3.0, but trying to link with OpenSSL >= 3.0. You need to manually edit CMakeCache.txt, replacing OpenSSL include/lib paths with consistent directories and files, or remove one of OpenSSL versions completely and start building from scratch.

matheusfillipe commented 1 year ago

Ok. Currently archlinux packages: openssl, openssl-1.0 and openssl-1.1 ships:

/usr/lib/openssl-1.0/{libcrypto.so,libssl.so}
/usr/lib/openssl-1.1/{libcrypto.so,libssl.so}
/usr/lib/{libcrypto.so,libssl.so}

And headers at:

/usr/include/openssl
/usr/include/openssl-1.0
/usr/include/openssl-1.1

If i clean the cmake cache and configure it:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr/local ..

It says

-- Found OpenSSL: /usr/lib/libcrypto.so (found version "3.0.7")
-- Found OpenSSL: /usr/include /usr/lib/libssl.so;/usr/lib/libcrypto.so

Which are the right paths for openssl 3 and this is the generated CMake:

CMakeCache.txt

But building like that will raise that error. The headers at /usr/include/openssl are for openssl3.0.

After I edited all OPENSSL references to ssl 1.1 it worked and my cmake file was like this: Found OpenSSL: /usr/include/openssl-1.1/ /usr/lib/openssl-1.1/libssl.so;/usr/lib/openssl-1.1/libcrypto.so CMakeCache.txt

levlam commented 1 year ago

But building like that will raise that error. The headers at /usr/include/openssl are for openssl3.0.

If you want to debug the issue, you can run in the build directory rm -f sqlite/CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o && make VERBOSE=1 tdsqlite to see exact compiler invocation. Then replace -o CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o in the shown build command with -E, run the command and grep output for "openssl/" to see the directories, in which include files were found. Some files are expected to be found in a directory different from "/usr/include/openssl/".

matheusfillipe commented 1 year ago
$ cd /home/matheus/Programs/td/build/sqlite && ccache /usr/bin/cc -DHAVE_USLEEP -DNDEBUG=1 -DOMIT_MEMLOCK -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_RECURSIVE_TRIGGERS=1 -DSQLITE_DEFAULT_SYNCHRONOUS=1 -DSQLITE_DISABLE_LFS -DSQLITE_ENABLE_FTS5 -DSQLITE_HAS_CODEC -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_DESERIALIZE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_TEMP_STORE=2 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/home/matheus/Programs/td/sqlite -ffunction-sections -fdata-sections -O3 -DNDEBUG -fPIC -Wno-deprecated-declarations -Wno-unused-variable -Wno-unused-const-variable -Wno-unused-function -Wno-return-local-addr -Wno-stringop-overflow -MD -MT sqlite/CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o -MF CMakeFiles/tdsqlite.dir/sqlite/sqlite3.c.o.d -E -c /home/matheus/Programs/td/sqlite/sqlite/sqlite3.c | grep "openssl/"
# 1 "/usr/local/include/openssl/opensslv.h" 1 3
# 1 "/usr/local/include/openssl/rand.h" 1 3
# 14 "/usr/local/include/openssl/rand.h" 3
# 1 "/usr/local/include/openssl/ossl_typ.h" 1 3
# 13 "/usr/local/include/openssl/ossl_typ.h" 3
# 14 "/usr/local/include/openssl/ossl_typ.h" 2 3
# 1 "/usr/local/include/openssl/e_os2.h" 1 3
# 13 "/usr/local/include/openssl/e_os2.h" 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 14 "/usr/local/include/openssl/e_os2.h" 2 3
# 243 "/usr/local/include/openssl/e_os2.h" 3
# 244 "/usr/local/include/openssl/e_os2.h" 2 3
# 20 "/usr/local/include/openssl/ossl_typ.h" 2 3
# 40 "/usr/local/include/openssl/ossl_typ.h" 3
# 78 "/usr/local/include/openssl/ossl_typ.h" 3
# 15 "/usr/local/include/openssl/rand.h" 2 3
# 1 "/usr/local/include/openssl/randerr.h" 1 3
# 17 "/usr/local/include/openssl/randerr.h" 3
# 17 "/usr/local/include/openssl/rand.h" 2 3
# 1 "/usr/local/include/openssl/evp.h" 1 3
# 13 "/usr/local/include/openssl/evp.h" 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 14 "/usr/local/include/openssl/evp.h" 2 3
# 1 "/usr/local/include/openssl/symhacks.h" 1 3
# 16 "/usr/local/include/openssl/evp.h" 2 3
# 1 "/usr/local/include/openssl/bio.h" 1 3
# 20 "/usr/local/include/openssl/bio.h" 3
# 1 "/usr/local/include/openssl/crypto.h" 1 3
# 15 "/usr/local/include/openssl/crypto.h" 3
# 16 "/usr/local/include/openssl/crypto.h" 2 3
# 1 "/usr/local/include/openssl/safestack.h" 1 3
# 13 "/usr/local/include/openssl/safestack.h" 3
# 1 "/usr/local/include/openssl/stack.h" 1 3
# 17 "/usr/local/include/openssl/stack.h" 3
# 14 "/usr/local/include/openssl/safestack.h" 2 3
# 149 "/usr/local/include/openssl/safestack.h" 3
# 159 "/usr/local/include/openssl/safestack.h" 3
# 24 "/usr/local/include/openssl/crypto.h" 2 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 27 "/usr/local/include/openssl/crypto.h" 2 3
# 1 "/usr/local/include/openssl/cryptoerr.h" 1 3
# 20 "/usr/local/include/openssl/cryptoerr.h" 3
# 28 "/usr/local/include/openssl/crypto.h" 2 3
# 61 "/usr/local/include/openssl/crypto.h" 3
# 86 "/usr/local/include/openssl/crypto.h" 3
# 115 "/usr/local/include/openssl/crypto.h" 3
# 146 "/usr/local/include/openssl/crypto.h" 3
# 229 "/usr/local/include/openssl/crypto.h" 3
# 256 "/usr/local/include/openssl/crypto.h" 3
# 322 "/usr/local/include/openssl/crypto.h" 3
# 353 "/usr/local/include/openssl/crypto.h" 3
# 387 "/usr/local/include/openssl/crypto.h" 3
# 415 "/usr/local/include/openssl/crypto.h" 3
# 416 "/usr/local/include/openssl/crypto.h" 2 3
# 431 "/usr/local/include/openssl/crypto.h" 3
# 21 "/usr/local/include/openssl/bio.h" 2 3
# 1 "/usr/local/include/openssl/bioerr.h" 1 3
# 17 "/usr/local/include/openssl/bioerr.h" 3
# 22 "/usr/local/include/openssl/bio.h" 2 3
# 177 "/usr/local/include/openssl/bio.h" 3
# 239 "/usr/local/include/openssl/bio.h" 3
# 490 "/usr/local/include/openssl/bio.h" 3
# 510 "/usr/local/include/openssl/bio.h" 3
# 532 "/usr/local/include/openssl/bio.h" 3
# 627 "/usr/local/include/openssl/bio.h" 3
# 755 "/usr/local/include/openssl/bio.h" 3
# 17 "/usr/local/include/openssl/evp.h" 2 3
# 1 "/usr/local/include/openssl/evperr.h" 1 3
# 17 "/usr/local/include/openssl/evperr.h" 3
# 18 "/usr/local/include/openssl/evp.h" 2 3
# 28 "/usr/local/include/openssl/evp.h" 3
# 1 "/usr/local/include/openssl/objects.h" 1 3
# 13 "/usr/local/include/openssl/objects.h" 3
# 1 "/usr/local/include/openssl/obj_mac.h" 1 3
# 14 "/usr/local/include/openssl/objects.h" 2 3
# 1 "/usr/local/include/openssl/asn1.h" 1 3
# 15 "/usr/local/include/openssl/asn1.h" 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 16 "/usr/local/include/openssl/asn1.h" 2 3
# 1 "/usr/local/include/openssl/asn1err.h" 1 3
# 17 "/usr/local/include/openssl/asn1err.h" 3
# 19 "/usr/local/include/openssl/asn1.h" 2 3
# 1 "/usr/local/include/openssl/bn.h" 1 3
# 18 "/usr/local/include/openssl/bn.h" 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 19 "/usr/local/include/openssl/bn.h" 2 3
# 1 "/usr/local/include/openssl/bnerr.h" 1 3
# 17 "/usr/local/include/openssl/bnerr.h" 3
# 22 "/usr/local/include/openssl/bn.h" 2 3
# 70 "/usr/local/include/openssl/bn.h" 3
# 88 "/usr/local/include/openssl/bn.h" 3
# 183 "/usr/local/include/openssl/bn.h" 3
# 428 "/usr/local/include/openssl/bn.h" 3
# 461 "/usr/local/include/openssl/bn.h" 3
# 533 "/usr/local/include/openssl/bn.h" 3
# 24 "/usr/local/include/openssl/asn1.h" 2 3
# 118 "/usr/local/include/openssl/asn1.h" 3
# 146 "/usr/local/include/openssl/asn1.h" 3
# 186 "/usr/local/include/openssl/asn1.h" 3
# 210 "/usr/local/include/openssl/asn1.h" 3
# 277 "/usr/local/include/openssl/asn1.h" 3
# 318 "/usr/local/include/openssl/asn1.h" 3
# 438 "/usr/local/include/openssl/asn1.h" 3
# 518 "/usr/local/include/openssl/asn1.h" 3
# 700 "/usr/local/include/openssl/asn1.h" 3
# 709 "/usr/local/include/openssl/asn1.h" 3
# 730 "/usr/local/include/openssl/asn1.h" 3
# 757 "/usr/local/include/openssl/asn1.h" 3
# 842 "/usr/local/include/openssl/asn1.h" 3
# 16 "/usr/local/include/openssl/objects.h" 2 3
# 1 "/usr/local/include/openssl/objectserr.h" 1 3
# 17 "/usr/local/include/openssl/objectserr.h" 3
# 17 "/usr/local/include/openssl/objects.h" 2 3
# 35 "/usr/local/include/openssl/objects.h" 3
# 155 "/usr/local/include/openssl/objects.h" 3
# 29 "/usr/local/include/openssl/evp.h" 2 3
# 76 "/usr/local/include/openssl/evp.h" 3
# 185 "/usr/local/include/openssl/evp.h" 3
# 362 "/usr/local/include/openssl/evp.h" 3
# 392 "/usr/local/include/openssl/evp.h" 3
# 439 "/usr/local/include/openssl/evp.h" 3
# 520 "/usr/local/include/openssl/evp.h" 3
# 533 "/usr/local/include/openssl/evp.h" 3
# 805 "/usr/local/include/openssl/evp.h" 3
# 961 "/usr/local/include/openssl/evp.h" 3
# 1118 "/usr/local/include/openssl/evp.h" 3
# 1141 "/usr/local/include/openssl/evp.h" 3
# 1323 "/usr/local/include/openssl/evp.h" 3
# 1 "/usr/local/include/openssl/hmac.h" 1 3
# 13 "/usr/local/include/openssl/hmac.h" 3
# 1 "/usr/local/include/openssl/opensslconf.h" 1 3
# 14 "/usr/local/include/openssl/hmac.h" 2 3
# 25 "/usr/local/include/openssl/hmac.h" 3
# 1 "/usr/local/include/openssl/err.h" 1 3
# 22 "/usr/local/include/openssl/err.h" 3
# 1 "/usr/local/include/openssl/lhash.h" 1 3
# 24 "/usr/local/include/openssl/lhash.h" 3
# 72 "/usr/local/include/openssl/lhash.h" 3
# 197 "/usr/local/include/openssl/lhash.h" 3
# 207 "/usr/local/include/openssl/lhash.h" 3
# 23 "/usr/local/include/openssl/err.h" 2 3
# 43 "/usr/local/include/openssl/err.h" 3
# 213 "/usr/local/include/openssl/err.h" 3

So /usr/local/include/openssl was the problem. I've probably manually compiled openssl once and completely forgot about it. After removing that directory and following the build steps again it all worked.

Thanks for the feedback @levlam