Programming languages

How to fix C++ error “undefined reference to `pthread_rwlock_init'”

Problem:

When compiling your C++ application, you see one or more of the following or similar error messages (complete error message log example shown below)

threads_pthread.c:(.text+0x4a): undefined reference to `pthread_rwlock_init'
threads_pthread.c:(.text+0x89): undefined reference to `pthread_rwlock_rdlock'
threads_pthread.c:(.text+0xa9): undefined reference to `pthread_rwlock_wrlock'
threads_pthread.c:(.text+0xc9): undefined reference to `pthread_rwlock_unlock'
threads_pthread.c:(.text+0xee): undefined reference to `pthread_rwlock_destroy'
threads_pthread.c:(.text+0x129): undefined reference to `pthread_once'
threads_pthread.c:(.text+0x149): undefined reference to `pthread_key_create'
threads_pthread.c:(.text+0x17b): undefined reference to `pthread_setspecific'
threads_pthread.c:(.text+0x19b): undefined reference to `pthread_key_delete'
threads_pthread.c:(.text+0x207): undefined reference to `pthread_once'
threads_pthread.c:(.text+0x167): undefined reference to `pthread_getspecific'

Solution:

You need to link the pthread library to your executable. When running gcc manually, use the -lpthread option, for example:

gcc -o myexe main.cpp -lpthread

When using CMake, use

add_executable(myexe main.cpp)
target_link_libraries(myexe pthread)

Full error log example:

/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_lock_new':
threads_pthread.c:(.text+0x4a): undefined reference to `pthread_rwlock_init'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_read_lock':
threads_pthread.c:(.text+0x89): undefined reference to `pthread_rwlock_rdlock'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_write_lock':
threads_pthread.c:(.text+0xa9): undefined reference to `pthread_rwlock_wrlock'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_unlock':
threads_pthread.c:(.text+0xc9): undefined reference to `pthread_rwlock_unlock'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_lock_free':
threads_pthread.c:(.text+0xee): undefined reference to `pthread_rwlock_destroy'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_run_once':
threads_pthread.c:(.text+0x129): undefined reference to `pthread_once'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_init_local':
threads_pthread.c:(.text+0x149): undefined reference to `pthread_key_create'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_set_local':
threads_pthread.c:(.text+0x17b): undefined reference to `pthread_setspecific'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_cleanup_local':
threads_pthread.c:(.text+0x19b): undefined reference to `pthread_key_delete'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `openssl_init_fork_handlers':
threads_pthread.c:(.text+0x207): undefined reference to `pthread_once'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(threads_pthread.o): in function `CRYPTO_THREAD_get_local':
threads_pthread.c:(.text+0x167): undefined reference to `pthread_getspecific'
/usr/bin/ld: /home/uli/.conan/data/openssl/1.1.1k/_/_/package/6af9cc7cb931c5ad942174fd7838eb655717c709/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_globallookup':

 

Posted by Uli Köhler in C/C++, GCC errors

How to fix C++ error “undefined reference to `MD5_Update'”

Problem:

When compiling your C++ application, you see one or more of the following or similar error messages (complete error message log example shown below)

/usr/bin/ld: md5.c:(.text+0x44): undefined reference to `MD5_Update'
/usr/bin/ld: md5.c:(.text+0x4f): undefined reference to `MD5_Final'
sha256.c:(.text+0x32): undefined reference to `SHA256_Init'
/usr/bin/ld: sha256.c:(.text+0x47): undefined reference to `SHA256_Update'
/usr/bin/ld: sha256.c:(.text+0x52): undefined reference to `SHA256_Final

Solution:

You need to link OpenSSL to your executable – the libraries that need to be linked are called crypto (libcrypto.so) and ssl (libssl.so). When running gcc manually, use the -lcrypto and -lssl options, for example:

gcc -o myexe main.cpp -lcrypto -lssl

When using CMake, use

add_executable(myexe main.cpp)
target_link_libraries(myexe crypto ssl)

Full error log example:

/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o): in function `Curl_md5it':
md5.c:(.text+0x2f): undefined reference to `MD5_Init'
/usr/bin/ld: md5.c:(.text+0x44): undefined reference to `MD5_Update'
/usr/bin/ld: md5.c:(.text+0x4f): undefined reference to `MD5_Final'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x0): undefined reference to `MD5_Init'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x8): undefined reference to `MD5_Update'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x10): undefined reference to `MD5_Final'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x20): undefined reference to `MD5_Init'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x28): undefined reference to `MD5_Update'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x30): undefined reference to `MD5_Final'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-sha256.o): in function `Curl_sha256it':
sha256.c:(.text+0x32): undefined reference to `SHA256_Init'
/usr/bin/ld: sha256.c:(.text+0x47): undefined reference to `SHA256_Update'
/usr/bin/ld: sha256.c:(.text+0x52): undefined reference to `SHA256_Final'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_sha256sum':
openssl.c:(.text+0x61): undefined reference to `EVP_MD_CTX_new'
/usr/bin/ld: openssl.c:(.text+0x69): undefined reference to `EVP_sha256'
/usr/bin/ld: openssl.c:(.text+0x76): undefined reference to `EVP_DigestInit_ex'
/usr/bin/ld: openssl.c:(.text+0x84): undefined reference to `EVP_DigestUpdate'
/usr/bin/ld: openssl.c:(.text+0x94): undefined reference to `EVP_DigestFinal_ex'
/usr/bin/ld: openssl.c:(.text+0x9c): undefined reference to `EVP_MD_CTX_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_md5sum':
openssl.c:(.text+0x101): undefined reference to `EVP_MD_CTX_new'
/usr/bin/ld: openssl.c:(.text+0x109): undefined reference to `EVP_md5'
/usr/bin/ld: openssl.c:(.text+0x116): undefined reference to `EVP_DigestInit_ex'
/usr/bin/ld: openssl.c:(.text+0x124): undefined reference to `EVP_DigestUpdate'
/usr/bin/ld: openssl.c:(.text+0x134): undefined reference to `EVP_DigestFinal_ex'
/usr/bin/ld: openssl.c:(.text+0x13c): undefined reference to `EVP_MD_CTX_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_engines_list':
openssl.c:(.text+0x17a): undefined reference to `ENGINE_get_first'
/usr/bin/ld: openssl.c:(.text+0x194): undefined reference to `ENGINE_get_next'
/usr/bin/ld: openssl.c:(.text+0x1a7): undefined reference to `ENGINE_get_id'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_close_all':
openssl.c:(.text+0x1f5): undefined reference to `ENGINE_finish'
/usr/bin/ld: openssl.c:(.text+0x201): undefined reference to `ENGINE_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ssl_tls_trace':
openssl.c:(.text+0x446): undefined reference to `SSL_alert_desc_string_long'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ssl_ui_writer':
openssl.c:(.text+0x645): undefined reference to `UI_get_string_type'
/usr/bin/ld: openssl.c:(.text+0x652): undefined reference to `UI_OpenSSL'
/usr/bin/ld: openssl.c:(.text+0x65a): undefined reference to `UI_method_get_writer'
/usr/bin/ld: openssl.c:(.text+0x674): undefined reference to `UI_get0_user_data'
/usr/bin/ld: openssl.c:(.text+0x681): undefined reference to `UI_get_input_flags'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ssl_ui_reader':
openssl.c:(.text+0x6b3): undefined reference to `UI_get_string_type'
/usr/bin/ld: openssl.c:(.text+0x6c0): undefined reference to `UI_OpenSSL'
/usr/bin/ld: openssl.c:(.text+0x6c8): undefined reference to `UI_method_get_reader'
/usr/bin/ld: openssl.c:(.text+0x6e4): undefined reference to `UI_get0_user_data'
/usr/bin/ld: openssl.c:(.text+0x6f4): undefined reference to `UI_get_input_flags'
/usr/bin/ld: openssl.c:(.text+0x706): undefined reference to `UI_set_result'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_data_pending':
openssl.c:(.text+0x746): undefined reference to `SSL_pending'
/usr/bin/ld: openssl.c:(.text+0x76f): undefined reference to `SSL_pending'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_version':
openssl.c:(.text+0x7a9): undefined reference to `OpenSSL_version_num'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_set_engine_default':
openssl.c:(.text+0x903): undefined reference to `ENGINE_set_default'
/usr/bin/ld: openssl.c:(.text+0x913): undefined reference to `ENGINE_get_id'
/usr/bin/ld: openssl.c:(.text+0x941): undefined reference to `ENGINE_get_id'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_seed.part.0':
openssl.c:(.text+0xbfe): undefined reference to `RAND_add'
/usr/bin/ld: openssl.c:(.text+0xc03): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0xc1f): undefined reference to `RAND_file_name'
/usr/bin/ld: openssl.c:(.text+0xc35): undefined reference to `RAND_load_file'
/usr/bin/ld: openssl.c:(.text+0xc3a): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0xc56): undefined reference to `RAND_status'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ossl_recv':
openssl.c:(.text+0xde7): undefined reference to `ERR_clear_error'
/usr/bin/ld: openssl.c:(.text+0xe15): undefined reference to `SSL_read'
/usr/bin/ld: openssl.c:(.text+0xe5f): undefined reference to `SSL_get_error'
/usr/bin/ld: openssl.c:(.text+0xe74): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0xfc4): undefined reference to `ERR_error_string_n'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_close':
openssl.c:(.text+0x102d): undefined reference to `SSL_shutdown'
/usr/bin/ld: openssl.c:(.text+0x103b): undefined reference to `SSL_set_connect_state'
/usr/bin/ld: openssl.c:(.text+0x1049): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x1063): undefined reference to `SSL_CTX_free'
/usr/bin/ld: openssl.c:(.text+0x1089): undefined reference to `SSL_shutdown'
/usr/bin/ld: openssl.c:(.text+0x1096): undefined reference to `SSL_set_connect_state'
/usr/bin/ld: openssl.c:(.text+0x10a3): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x10bc): undefined reference to `SSL_CTX_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_random':
openssl.c:(.text+0x10fb): undefined reference to `RAND_bytes'
/usr/bin/ld: openssl.c:(.text+0x111c): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0x113f): undefined reference to `RAND_load_file'
/usr/bin/ld: openssl.c:(.text+0x1144): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0x1161): undefined reference to `RAND_status'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ossl_new_session_cb':
openssl.c:(.text+0x11c7): undefined reference to `SSL_get_ex_data'
/usr/bin/ld: openssl.c:(.text+0x11dd): undefined reference to `SSL_get_ex_data'
/usr/bin/ld: openssl.c:(.text+0x123f): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: openssl.c:(.text+0x126f): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_init':
openssl.c:(.text+0x138c): undefined reference to `OPENSSL_load_builtin_modules'
/usr/bin/ld: openssl.c:(.text+0x1391): undefined reference to `ENGINE_load_builtin_engines'
/usr/bin/ld: openssl.c:(.text+0x139f): undefined reference to `CONF_modules_load_file'
/usr/bin/ld: openssl.c:(.text+0x13e7): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: openssl.c:(.text+0x1487): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_set_engine':
openssl.c:(.text+0x14cf): undefined reference to `ENGINE_by_id'
/usr/bin/ld: openssl.c:(.text+0x14ec): undefined reference to `ENGINE_finish'
/usr/bin/ld: openssl.c:(.text+0x14f8): undefined reference to `ENGINE_free'
/usr/bin/ld: openssl.c:(.text+0x150b): undefined reference to `ENGINE_init'
/usr/bin/ld: openssl.c:(.text+0x154f): undefined reference to `ENGINE_free'
/usr/bin/ld: openssl.c:(.text+0x1554): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x156b): undefined reference to `ERR_error_string_n'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_shutdown':
openssl.c:(.text+0x16b8): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x1701): undefined reference to `ERR_clear_error'
/usr/bin/ld: openssl.c:(.text+0x171e): undefined reference to `SSL_read'
/usr/bin/ld: openssl.c:(.text+0x1730): undefined reference to `SSL_get_error'
/usr/bin/ld: openssl.c:(.text+0x177b): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x1831): undefined reference to `SSL_get_shutdown'
/usr/bin/ld: openssl.c:(.text+0x1861): undefined reference to `SSL_shutdown'
/usr/bin/ld: openssl.c:(.text+0x1895): undefined reference to `ERR_error_string_n'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ossl_connect_step2':
openssl.c:(.text+0x1a13): undefined reference to `ERR_clear_error'
/usr/bin/ld: openssl.c:(.text+0x1a2c): undefined reference to `SSL_connect'
/usr/bin/ld: openssl.c:(.text+0x1a47): undefined reference to `SSL_get_error'
/usr/bin/ld: openssl.c:(.text+0x1af2): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x1b24): undefined reference to `SSL_get_verify_result'
/usr/bin/ld: openssl.c:(.text+0x1b44): undefined reference to `X509_verify_cert_error_string'
/usr/bin/ld: openssl.c:(.text+0x1bf7): undefined reference to `SSL_get_current_cipher'
/usr/bin/ld: openssl.c:(.text+0x1bff): undefined reference to `SSL_CIPHER_get_name'
/usr/bin/ld: openssl.c:(.text+0x1c1e): undefined reference to `SSL_version'
/usr/bin/ld: openssl.c:(.text+0x1c96): undefined reference to `SSL_get0_alpn_selected'
/usr/bin/ld: openssl.c:(.text+0x1d2e): undefined reference to `ERR_error_string_n'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ossl_send':
openssl.c:(.text+0x1fe6): undefined reference to `ERR_clear_error'
/usr/bin/ld: openssl.c:(.text+0x2015): undefined reference to `SSL_write'
/usr/bin/ld: openssl.c:(.text+0x205e): undefined reference to `SSL_get_error'
/usr/bin/ld: openssl.c:(.text+0x2080): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x20ff): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x219b): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x2213): undefined reference to `ERR_error_string_n'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `servercert':
openssl.c:(.text+0x249b): undefined reference to `BIO_s_mem'
/usr/bin/ld: openssl.c:(.text+0x24a3): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x24cc): undefined reference to `SSL_get_peer_certificate'
/usr/bin/ld: openssl.c:(.text+0x2541): undefined reference to `X509_get_subject_name'
/usr/bin/ld: openssl.c:(.text+0x2549): undefined reference to `BIO_s_mem'
/usr/bin/ld: openssl.c:(.text+0x2551): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x2576): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: openssl.c:(.text+0x2596): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x25d6): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x2614): undefined reference to `X509_get0_notBefore'
/usr/bin/ld: openssl.c:(.text+0x2624): undefined reference to `ASN1_TIME_print'
/usr/bin/ld: openssl.c:(.text+0x2636): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2663): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2670): undefined reference to `X509_get0_notAfter'
/usr/bin/ld: openssl.c:(.text+0x267b): undefined reference to `ASN1_TIME_print'
/usr/bin/ld: openssl.c:(.text+0x268d): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x26ba): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x26c2): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x2786): undefined reference to `X509_get_ext_d2i'
/usr/bin/ld: openssl.c:(.text+0x279a): undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: openssl.c:(.text+0x27ef): undefined reference to `OPENSSL_sk_value'
/usr/bin/ld: openssl.c:(.text+0x281c): undefined reference to `GENERAL_NAMES_free'
/usr/bin/ld: openssl.c:(.text+0x283c): undefined reference to `X509_get_issuer_name'
/usr/bin/ld: openssl.c:(.text+0x2844): undefined reference to `BIO_s_mem'
/usr/bin/ld: openssl.c:(.text+0x284c): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x286a): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: openssl.c:(.text+0x2888): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x28c7): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x2913): undefined reference to `BIO_s_file'
/usr/bin/ld: openssl.c:(.text+0x291b): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x2956): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x296c): undefined reference to `PEM_read_bio_X509'
/usr/bin/ld: openssl.c:(.text+0x298d): undefined reference to `X509_check_issued'
/usr/bin/ld: openssl.c:(.text+0x29cb): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x29d3): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x29e5): undefined reference to `SSL_get_verify_result'
/usr/bin/ld: openssl.c:(.text+0x2a3b): undefined reference to `X509_verify_cert_error_string'
/usr/bin/ld: openssl.c:(.text+0x2b08): undefined reference to `X509_get_X509_PUBKEY'
/usr/bin/ld: openssl.c:(.text+0x2b12): undefined reference to `i2d_X509_PUBKEY'
/usr/bin/ld: openssl.c:(.text+0x2b3f): undefined reference to `X509_get_X509_PUBKEY'
/usr/bin/ld: openssl.c:(.text+0x2b4f): undefined reference to `i2d_X509_PUBKEY'
/usr/bin/ld: openssl.c:(.text+0x2b94): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x2c2d): undefined reference to `SSL_get_peer_cert_chain'
/usr/bin/ld: openssl.c:(.text+0x2c43): undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: openssl.c:(.text+0x2c60): undefined reference to `BIO_s_mem'
/usr/bin/ld: openssl.c:(.text+0x2c68): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x2cb8): undefined reference to `OPENSSL_sk_value'
/usr/bin/ld: openssl.c:(.text+0x2ccf): undefined reference to `X509_get_subject_name'
/usr/bin/ld: openssl.c:(.text+0x2ce1): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: openssl.c:(.text+0x2cf8): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2d22): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2d2a): undefined reference to `X509_get_issuer_name'
/usr/bin/ld: openssl.c:(.text+0x2d3c): undefined reference to `X509_NAME_print_ex'
/usr/bin/ld: openssl.c:(.text+0x2d4e): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2d78): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2d80): undefined reference to `X509_get_version'
/usr/bin/ld: openssl.c:(.text+0x2d94): undefined reference to `BIO_printf'
/usr/bin/ld: openssl.c:(.text+0x2da6): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2dd0): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2dd8): undefined reference to `X509_get_serialNumber'
/usr/bin/ld: openssl.c:(.text+0x2e1a): undefined reference to `BIO_printf'
/usr/bin/ld: openssl.c:(.text+0x2e34): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2e5e): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2e88): undefined reference to `X509_get0_signature'
/usr/bin/ld: openssl.c:(.text+0x2ea0): undefined reference to `i2a_ASN1_OBJECT'
/usr/bin/ld: openssl.c:(.text+0x2eb4): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2ede): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2ee6): undefined reference to `X509_get_X509_PUBKEY'
/usr/bin/ld: openssl.c:(.text+0x2f01): undefined reference to `X509_PUBKEY_get0_param'
/usr/bin/ld: openssl.c:(.text+0x2f16): undefined reference to `i2a_ASN1_OBJECT'
/usr/bin/ld: openssl.c:(.text+0x2f2a): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2f54): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2f5c): undefined reference to `X509_get0_extensions'
/usr/bin/ld: openssl.c:(.text+0x2f67): undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: openssl.c:(.text+0x2f9e): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x2fc4): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x2fcc): undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: openssl.c:(.text+0x2fde): undefined reference to `OPENSSL_sk_value'
/usr/bin/ld: openssl.c:(.text+0x2fe6): undefined reference to `BIO_s_mem'
/usr/bin/ld: openssl.c:(.text+0x2fee): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x3002): undefined reference to `X509_EXTENSION_get_object'
/usr/bin/ld: openssl.c:(.text+0x3014): undefined reference to `i2t_ASN1_OBJECT'
/usr/bin/ld: openssl.c:(.text+0x3023): undefined reference to `X509V3_EXT_print'
/usr/bin/ld: openssl.c:(.text+0x3033): undefined reference to `X509_EXTENSION_get_data'
/usr/bin/ld: openssl.c:(.text+0x303e): undefined reference to `ASN1_STRING_print'
/usr/bin/ld: openssl.c:(.text+0x3125): undefined reference to `SSL_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3150): undefined reference to `d2i_OCSP_RESPONSE'
/usr/bin/ld: openssl.c:(.text+0x3164): undefined reference to `OCSP_response_status'
/usr/bin/ld: openssl.c:(.text+0x3177): undefined reference to `OCSP_response_get1_basic'
/usr/bin/ld: openssl.c:(.text+0x3195): undefined reference to `SSL_get_peer_cert_chain'
/usr/bin/ld: openssl.c:(.text+0x31a4): undefined reference to `SSL_CTX_get_cert_store'
/usr/bin/ld: openssl.c:(.text+0x31bc): undefined reference to `OCSP_basic_verify'
/usr/bin/ld: openssl.c:(.text+0x31cc): undefined reference to `OCSP_resp_count'
/usr/bin/ld: openssl.c:(.text+0x31e0): undefined reference to `OCSP_resp_get0'
/usr/bin/ld: openssl.c:(.text+0x3209): undefined reference to `OCSP_single_get0_status'
/usr/bin/ld: openssl.c:(.text+0x322c): undefined reference to `OCSP_check_validity'
/usr/bin/ld: openssl.c:(.text+0x323c): undefined reference to `OCSP_cert_status_str'
/usr/bin/ld: openssl.c:(.text+0x326c): undefined reference to `OCSP_BASICRESP_free'
/usr/bin/ld: openssl.c:(.text+0x3274): undefined reference to `OCSP_RESPONSE_free'
/usr/bin/ld: openssl.c:(.text+0x328c): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x3386): undefined reference to `X509_get0_notBefore'
/usr/bin/ld: openssl.c:(.text+0x3391): undefined reference to `ASN1_TIME_print'
/usr/bin/ld: openssl.c:(.text+0x33a8): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x33d2): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x33da): undefined reference to `X509_get0_notAfter'
/usr/bin/ld: openssl.c:(.text+0x33e5): undefined reference to `ASN1_TIME_print'
/usr/bin/ld: openssl.c:(.text+0x33f7): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3421): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3429): undefined reference to `X509_get_pubkey'
/usr/bin/ld: openssl.c:(.text+0x343d): undefined reference to `EVP_PKEY_id'
/usr/bin/ld: openssl.c:(.text+0x3460): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x3478): undefined reference to `PEM_write_bio_X509'
/usr/bin/ld: openssl.c:(.text+0x348c): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x34b9): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x34cb): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x3502): undefined reference to `BIO_printf'
/usr/bin/ld: openssl.c:(.text+0x3523): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x354d): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x359b): undefined reference to `BIO_puts'
/usr/bin/ld: openssl.c:(.text+0x35ac): undefined reference to `GENERAL_NAMES_free'
/usr/bin/ld: openssl.c:(.text+0x35c3): undefined reference to `X509_get_subject_name'
/usr/bin/ld: openssl.c:(.text+0x35e5): undefined reference to `X509_NAME_get_index_by_NID'
/usr/bin/ld: openssl.c:(.text+0x365e): undefined reference to `CRYPTO_free'
/usr/bin/ld: openssl.c:(.text+0x3674): undefined reference to `EVP_PKEY_get0_DSA'
/usr/bin/ld: openssl.c:(.text+0x3694): undefined reference to `DSA_get0_pqg'
/usr/bin/ld: openssl.c:(.text+0x36a6): undefined reference to `DSA_get0_key'
/usr/bin/ld: openssl.c:(.text+0x36e4): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x36fe): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3729): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3771): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3783): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x37ae): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x37f6): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3808): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3833): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x387b): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x388d): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x38b8): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x38cc): undefined reference to `EVP_PKEY_get0_RSA'
/usr/bin/ld: openssl.c:(.text+0x38e3): undefined reference to `RSA_get0_key'
/usr/bin/ld: openssl.c:(.text+0x38f0): undefined reference to `BN_num_bits'
/usr/bin/ld: openssl.c:(.text+0x3903): undefined reference to `BIO_printf'
/usr/bin/ld: openssl.c:(.text+0x3917): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3941): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x397f): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3999): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x39c4): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x39f4): undefined reference to `EVP_PKEY_get0_DH'
/usr/bin/ld: openssl.c:(.text+0x3a14): undefined reference to `DH_get0_pqg'
/usr/bin/ld: openssl.c:(.text+0x3a26): undefined reference to `DH_get0_key'
/usr/bin/ld: openssl.c:(.text+0x3a64): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3a7e): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3aa9): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3af1): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3b03): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3b2e): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3b76): undefined reference to `BN_print'
/usr/bin/ld: openssl.c:(.text+0x3b88): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3bb3): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x3be9): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x3c45): undefined reference to `ASN1_STRING_get0_data'
/usr/bin/ld: openssl.c:(.text+0x3c4e): undefined reference to `ASN1_STRING_length'
/usr/bin/ld: openssl.c:(.text+0x3c65): undefined reference to `ASN1_STRING_get0_data'
/usr/bin/ld: openssl.c:(.text+0x3c71): undefined reference to `ASN1_STRING_length'
/usr/bin/ld: openssl.c:(.text+0x3cbd): undefined reference to `GENERAL_NAMES_free'
/usr/bin/ld: openssl.c:(.text+0x3cd5): undefined reference to `ASN1_STRING_get0_data'
/usr/bin/ld: openssl.c:(.text+0x3ce1): undefined reference to `ASN1_STRING_length'
/usr/bin/ld: openssl.c:(.text+0x3d99): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x3de3): undefined reference to `OCSP_BASICRESP_free'
/usr/bin/ld: openssl.c:(.text+0x3deb): undefined reference to `OCSP_RESPONSE_free'
/usr/bin/ld: openssl.c:(.text+0x3e41): undefined reference to `OCSP_crl_reason_str'
/usr/bin/ld: openssl.c:(.text+0x3e95): undefined reference to `OCSP_RESPONSE_free'
/usr/bin/ld: openssl.c:(.text+0x3f5e): undefined reference to `X509_NAME_get_entry'
/usr/bin/ld: openssl.c:(.text+0x3f66): undefined reference to `X509_NAME_ENTRY_get_data'
/usr/bin/ld: openssl.c:(.text+0x3f7a): undefined reference to `ASN1_STRING_type'
/usr/bin/ld: openssl.c:(.text+0x3f93): undefined reference to `ASN1_STRING_to_UTF8'
/usr/bin/ld: openssl.c:(.text+0x3ff7): undefined reference to `X509_verify_cert_error_string'
/usr/bin/ld: openssl.c:(.text+0x402c): undefined reference to `OCSP_response_status_str'
/usr/bin/ld: openssl.c:(.text+0x40a9): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x40c1): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x4119): undefined reference to `CRYPTO_free'
/usr/bin/ld: openssl.c:(.text+0x4169): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x4170): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x4209): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x422d): undefined reference to `OCSP_BASICRESP_free'
/usr/bin/ld: openssl.c:(.text+0x4235): undefined reference to `OCSP_RESPONSE_free'
/usr/bin/ld: openssl.c:(.text+0x4242): undefined reference to `ASN1_STRING_length'
/usr/bin/ld: openssl.c:(.text+0x4264): undefined reference to `CRYPTO_malloc'
/usr/bin/ld: openssl.c:(.text+0x4280): undefined reference to `ASN1_STRING_get0_data'
/usr/bin/ld: openssl.c:(.text+0x42a9): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x42cc): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x432e): undefined reference to `X509_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `ossl_connect_step1':
openssl.c:(.text+0x4543): undefined reference to `TLS_client_method'
/usr/bin/ld: openssl.c:(.text+0x4567): undefined reference to `SSL_CTX_free'
/usr/bin/ld: openssl.c:(.text+0x4580): undefined reference to `SSL_CTX_new'
/usr/bin/ld: openssl.c:(.text+0x45b4): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x465a): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x46be): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x46e1): undefined reference to `SSL_CTX_set_options'
/usr/bin/ld: openssl.c:(.text+0x4802): undefined reference to `SSL_CTX_set_default_passwd_cb_userdata'
/usr/bin/ld: openssl.c:(.text+0x4811): undefined reference to `SSL_CTX_set_default_passwd_cb'
/usr/bin/ld: openssl.c:(.text+0x4846): undefined reference to `BIO_s_file'
/usr/bin/ld: openssl.c:(.text+0x484e): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x4871): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x4883): undefined reference to `d2i_PKCS12_bio'
/usr/bin/ld: openssl.c:(.text+0x488e): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x489c): undefined reference to `PKCS12_PBE_add'
/usr/bin/ld: openssl.c:(.text+0x48bb): undefined reference to `PKCS12_parse'
/usr/bin/ld: openssl.c:(.text+0x48cb): undefined reference to `PKCS12_free'
/usr/bin/ld: openssl.c:(.text+0x48da): undefined reference to `SSL_CTX_use_certificate'
/usr/bin/ld: openssl.c:(.text+0x48e8): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x490b): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x495f): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x4969): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x4970): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x497d): undefined reference to `OPENSSL_sk_pop_free'
/usr/bin/ld: openssl.c:(.text+0x4991): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0x49b8): undefined reference to `RAND_load_file'
/usr/bin/ld: openssl.c:(.text+0x49bd): undefined reference to `RAND_status'
/usr/bin/ld: openssl.c:(.text+0x4b4b): undefined reference to `EVP_PKEY_get1_RSA'
/usr/bin/ld: openssl.c:(.text+0x4b58): undefined reference to `RSA_flags'
/usr/bin/ld: openssl.c:(.text+0x4b64): undefined reference to `RSA_free'
/usr/bin/ld: openssl.c:(.text+0x4b6c): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x4baf): undefined reference to `SSL_CTX_set_cipher_list'
/usr/bin/ld: openssl.c:(.text+0x4bff): undefined reference to `SSL_CTX_set_ciphersuites'
/usr/bin/ld: openssl.c:(.text+0x4c2f): undefined reference to `SSL_CTX_set_post_handshake_auth'
/usr/bin/ld: openssl.c:(.text+0x4c5b): undefined reference to `X509_LOOKUP_file'
/usr/bin/ld: openssl.c:(.text+0x4c75): undefined reference to `SSL_CTX_get_cert_store'
/usr/bin/ld: openssl.c:(.text+0x4c80): undefined reference to `X509_STORE_add_lookup'
/usr/bin/ld: openssl.c:(.text+0x4c9e): undefined reference to `X509_load_crl_file'
/usr/bin/ld: openssl.c:(.text+0x4cc6): undefined reference to `SSL_CTX_get_cert_store'
/usr/bin/ld: openssl.c:(.text+0x4cd3): undefined reference to `X509_STORE_set_flags'
/usr/bin/ld: openssl.c:(.text+0x4d30): undefined reference to `SSL_CTX_set_verify'
/usr/bin/ld: openssl.c:(.text+0x4d55): undefined reference to `SSL_CTX_set_keylog_callback'
/usr/bin/ld: openssl.c:(.text+0x4d78): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x4d8e): undefined reference to `SSL_CTX_sess_set_new_cb'
/usr/bin/ld: openssl.c:(.text+0x4df9): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x4e09): undefined reference to `SSL_new'
/usr/bin/ld: openssl.c:(.text+0x4e4f): undefined reference to `SSL_set_connect_state'
/usr/bin/ld: openssl.c:(.text+0x4ec6): undefined reference to `BIO_f_ssl'
/usr/bin/ld: openssl.c:(.text+0x4ece): undefined reference to `BIO_new'
/usr/bin/ld: openssl.c:(.text+0x4eeb): undefined reference to `BIO_ctrl'
/usr/bin/ld: openssl.c:(.text+0x4f01): undefined reference to `SSL_set_bio'
/usr/bin/ld: openssl.c:(.text+0x4f42): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x4f62): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x4fa0): undefined reference to `SSL_CTX_set_msg_callback'
/usr/bin/ld: openssl.c:(.text+0x4fb9): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x5022): undefined reference to `SSL_CTX_set_alpn_protos'
/usr/bin/ld: openssl.c:(.text+0x5045): undefined reference to `SSL_CTX_set_next_proto_select_cb'
/usr/bin/ld: openssl.c:(.text+0x50c5): undefined reference to `SSL_CTX_use_certificate_chain_file'
/usr/bin/ld: openssl.c:(.text+0x5108): undefined reference to `SSL_CTX_use_PrivateKey_file'
/usr/bin/ld: openssl.c:(.text+0x511b): undefined reference to `SSL_new'
/usr/bin/ld: openssl.c:(.text+0x512f): undefined reference to `SSL_get_certificate'
/usr/bin/ld: openssl.c:(.text+0x5141): undefined reference to `X509_get_pubkey'
/usr/bin/ld: openssl.c:(.text+0x514c): undefined reference to `SSL_get_privatekey'
/usr/bin/ld: openssl.c:(.text+0x5157): undefined reference to `EVP_PKEY_copy_parameters'
/usr/bin/ld: openssl.c:(.text+0x515f): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x5167): undefined reference to `SSL_get_privatekey'
/usr/bin/ld: openssl.c:(.text+0x5172): undefined reference to `EVP_PKEY_id'
/usr/bin/ld: openssl.c:(.text+0x5183): undefined reference to `SSL_free'
/usr/bin/ld: openssl.c:(.text+0x518d): undefined reference to `SSL_CTX_check_private_key'
/usr/bin/ld: openssl.c:(.text+0x51ec): undefined reference to `SSL_CTX_set_srp_username'
/usr/bin/ld: openssl.c:(.text+0x521d): undefined reference to `SSL_CTX_set_srp_password'
/usr/bin/ld: openssl.c:(.text+0x5272): undefined reference to `SSL_CTX_set_cipher_list'
/usr/bin/ld: openssl.c:(.text+0x52ba): undefined reference to `SSL_CTX_load_verify_locations'
/usr/bin/ld: openssl.c:(.text+0x5331): undefined reference to `ERR_peek_error'
/usr/bin/ld: openssl.c:(.text+0x5354): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x53c0): undefined reference to `SSL_set_fd'
/usr/bin/ld: openssl.c:(.text+0x53cd): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x53f0): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x55b9): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: openssl.c:(.text+0x560d): undefined reference to `SSL_set_session'
/usr/bin/ld: openssl.c:(.text+0x5672): undefined reference to `SSL_ctrl'
/usr/bin/ld: openssl.c:(.text+0x56a5): undefined reference to `SSL_ctrl'
/usr/bin/ld: openssl.c:(.text+0x5793): undefined reference to `SSL_CTX_get_cert_store'
/usr/bin/ld: openssl.c:(.text+0x57a0): undefined reference to `X509_STORE_set_flags'
/usr/bin/ld: openssl.c:(.text+0x586d): undefined reference to `SSL_CTX_set_default_passwd_cb_userdata'
/usr/bin/ld: openssl.c:(.text+0x587c): undefined reference to `SSL_CTX_set_default_passwd_cb'
/usr/bin/ld: openssl.c:(.text+0x58c0): undefined reference to `ENGINE_ctrl'
/usr/bin/ld: openssl.c:(.text+0x58f3): undefined reference to `ENGINE_ctrl_cmd'
/usr/bin/ld: openssl.c:(.text+0x5916): undefined reference to `SSL_CTX_use_certificate'
/usr/bin/ld: openssl.c:(.text+0x593f): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x5958): undefined reference to `SSL_CTX_use_certificate_file'
/usr/bin/ld: openssl.c:(.text+0x5966): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x5989): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x5a70): undefined reference to `SSL_set_ex_data'
/usr/bin/ld: openssl.c:(.text+0x5a90): undefined reference to `SSL_set_ex_data'
/usr/bin/ld: openssl.c:(.text+0x5ab3): undefined reference to `CRYPTO_get_ex_new_index'
/usr/bin/ld: openssl.c:(.text+0x5bc6): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x5be9): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x5cc6): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x5ce1): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x5d5f): undefined reference to `SSL_CTX_use_PrivateKey_file'
/usr/bin/ld: openssl.c:(.text+0x5dc3): undefined reference to `BIO_free'
/usr/bin/ld: openssl.c:(.text+0x5dcd): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x5df0): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x5e4c): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x5e77): undefined reference to `UI_create_method'
/usr/bin/ld: openssl.c:(.text+0x5e88): undefined reference to `UI_OpenSSL'
/usr/bin/ld: openssl.c:(.text+0x5e90): undefined reference to `UI_method_get_opener'
/usr/bin/ld: openssl.c:(.text+0x5e9b): undefined reference to `UI_method_set_opener'
/usr/bin/ld: openssl.c:(.text+0x5ea0): undefined reference to `UI_OpenSSL'
/usr/bin/ld: openssl.c:(.text+0x5ea8): undefined reference to `UI_method_get_closer'
/usr/bin/ld: openssl.c:(.text+0x5eb3): undefined reference to `UI_method_set_closer'
/usr/bin/ld: openssl.c:(.text+0x5ec2): undefined reference to `UI_method_set_reader'
/usr/bin/ld: openssl.c:(.text+0x5ed1): undefined reference to `UI_method_set_writer'
/usr/bin/ld: openssl.c:(.text+0x5eef): undefined reference to `ENGINE_load_private_key'
/usr/bin/ld: openssl.c:(.text+0x5efa): undefined reference to `UI_destroy_method'
/usr/bin/ld: openssl.c:(.text+0x5f10): undefined reference to `SSL_CTX_use_PrivateKey'
/usr/bin/ld: openssl.c:(.text+0x5f34): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x5f3e): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x5f61): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x5fb3): undefined reference to `PKCS12_free'
/usr/bin/ld: openssl.c:(.text+0x5fc7): undefined reference to `SSL_CTX_use_PrivateKey'
/usr/bin/ld: openssl.c:(.text+0x600c): undefined reference to `ERR_get_error'
/usr/bin/ld: openssl.c:(.text+0x602f): undefined reference to `ERR_error_string_n'
/usr/bin/ld: openssl.c:(.text+0x60c2): undefined reference to `SSL_CTX_check_private_key'
/usr/bin/ld: openssl.c:(.text+0x60f0): undefined reference to `OPENSSL_sk_pop'
/usr/bin/ld: openssl.c:(.text+0x60fe): undefined reference to `SSL_CTX_add_client_CA'
/usr/bin/ld: openssl.c:(.text+0x6118): undefined reference to `SSL_CTX_ctrl'
/usr/bin/ld: openssl.c:(.text+0x612e): undefined reference to `OPENSSL_sk_num'
/usr/bin/ld: openssl.c:(.text+0x6143): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x614d): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x6154): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x6161): undefined reference to `OPENSSL_sk_pop_free'
/usr/bin/ld: openssl.c:(.text+0x61af): undefined reference to `EVP_PKEY_free'
/usr/bin/ld: openssl.c:(.text+0x628c): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x62ac): undefined reference to `X509_free'
/usr/bin/ld: openssl.c:(.text+0x62d8): undefined reference to `SSL_CTX_use_PrivateKey_file'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-openssl.o): in function `Curl_ossl_session_free':
openssl.c:(.text+0x225): undefined reference to `SSL_SESSION_free'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-curl_ntlm_core.o): in function `setup_des_key':
curl_ntlm_core.c:(.text+0x98): undefined reference to `DES_set_odd_parity'
/usr/bin/ld: curl_ntlm_core.c:(.text+0xa3): undefined reference to `DES_set_key'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-curl_ntlm_core.o): in function `Curl_ntlm_core_lm_resp':
curl_ntlm_core.c:(.text+0x117): undefined reference to `DES_ecb_encrypt'
/usr/bin/ld: curl_ntlm_core.c:(.text+0x137): undefined reference to `DES_ecb_encrypt'
/usr/bin/ld: curl_ntlm_core.c:(.text+0x157): undefined reference to `DES_ecb_encrypt'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-curl_ntlm_core.o): in function `Curl_ntlm_core_mk_lm_hash':
curl_ntlm_core.c:(.text+0x23c): undefined reference to `DES_ecb_encrypt'
/usr/bin/ld: curl_ntlm_core.c:(.text+0x264): undefined reference to `DES_ecb_encrypt'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-md4.o): in function `Curl_md4it':
md4.c:(.text+0x2f): undefined reference to `MD4_Init'
/usr/bin/ld: md4.c:(.text+0x44): undefined reference to `MD4_Update'
/usr/bin/ld: md4.c:(.text+0x4f): undefined reference to `MD4_Final'

 

Posted by Uli Köhler in C/C++, GCC errors

How to fix C++ error “undefined reference to `zlibVersion'”

Problem:

When compiling your C++ application, you see one or more of the following error message (complete error message log example shown below)

version.c:(.text+0x5d): undefined reference to `zlibVersion'
content_encoding.c:(.text+0x1f8): undefined reference to `inflateInit_'
content_encoding.c:(.text+0x2b5): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0x401): undefined reference to `inflateInit2_'

Solution:

You need to link zlib to your executable – the library that needs to be linked is called z (libz.so). When running gcc manually, use the -lz option, for example:

gcc -o myexe main.cpp -lz

When using CMake, use

add_executable(myexe main.cpp)
target_link_libraries(myexe z)

Full error log example:

/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-version.o): in function `curl_version':
version.c:(.text+0x5d): undefined reference to `zlibVersion'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-version.o): in function `curl_version_info':
version.c:(.text+0x169): undefined reference to `zlibVersion'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `deflate_init_writer':
content_encoding.c:(.text+0x1f8): undefined reference to `inflateInit_'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `gzip_close_writer':
content_encoding.c:(.text+0x2b5): undefined reference to `inflateEnd'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `deflate_close_writer':
content_encoding.c:(.text+0x345): undefined reference to `inflateEnd'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `gzip_init_writer':
content_encoding.c:(.text+0x3ce): undefined reference to `zlibVersion'
/usr/bin/ld: content_encoding.c:(.text+0x401): undefined reference to `inflateInit2_'
/usr/bin/ld: content_encoding.c:(.text+0x429): undefined reference to `inflateInit2_'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `inflate_stream':
content_encoding.c:(.text+0x50e): undefined reference to `inflate'
/usr/bin/ld: content_encoding.c:(.text+0x691): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0x6f4): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0x724): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0x73d): undefined reference to `inflateInit2_'
/usr/bin/ld: content_encoding.c:(.text+0x7d9): undefined reference to `inflateEnd'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `deflate_unencode_write':
content_encoding.c:(.text+0x8c0): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0x8f1): undefined reference to `inflateEnd'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o): in function `gzip_unencode_write':
content_encoding.c:(.text+0xa40): undefined reference to `inflateEnd'
/usr/bin/ld: content_encoding.c:(.text+0xb07): undefined reference to `inflateEnd'
/usr/bin/ld: /home/uli/.conan/data/libcurl/7.69.1/_/_/package/d66c87f35a2a176e10af56a7f32a51d6e7b43e26/lib/libcurl.a(libcurl_la-content_encoding.o):content_encoding.c:(.text+0xc02): more undefined references to `inflateEnd' follow

 

Posted by Uli Köhler in C/C++, GCC errors

How to run jpegoptim recursively for each file in a directory

This command will run jpegoptim in lossless mode for each .jpg file in a folder recursively. This is how I reduce the size of my photo & image collection.

find . \( -iname \*.jpg -or -iname \*.jpeg \) -print0 | xargs -P 4 -n 1 -0 jpegoptim

See How to use xargs in parallel for details on  the -P 4 -n 1 syntax which runs 4 jpegoptim processes in parallel.

Note that the output may be scrambled due to 4 processes running in parallel, but it’s typically 4 times faster using this approach. You can also use

find . \( -iname \*.jpg -or -iname \*.jpeg \) -print0 | xargs -0 jpegoptim

to run just one jpegoptim process in parallel.

Posted by Uli Köhler in Shell

How to remove every .plist file on the command line

Use this command to remove every .plist file in the current folder recursively:

find . -name "*.plist" -exec rm -v {} \;

Since .plist files are metadata from MacOS applications, it’s often fine to remove them from backups, NAS storage etc.

Posted by Uli Köhler in Shell

How to make video from Matplotlib plots

First, you need to ensure that your plots are saved all with the same name pattern containing the frame number (starting at 1) which must be padded with zeros! For example, your plot should be named myplot_000001.png or myplot_0123. This can be done using, for example, using

fig.savefig(f'myplots/myplot_{timestep:06d}.png')

06d pads the number (in the timestep variable) up to 6 digits in total.

Now, use ffmpeg like this to create the video:

ffmpeg -f image2 -framerate 25 -i myplots/myplot_%06d.png -vcodec libx264 -crf 22 video.mp4

 

Posted by Uli Köhler in Data science, Python

How to fix Conan CMake “Could NOT find OpenSSL”

Problem:

When building your conan package, you see this CMake error:

CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
  OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.16/Modules/FindOpenSSL.cmake:447 (find_package_handle_standard_args)
  ../_deps/curl-src/CMakeLists.txt:365 (find_package)

even though your conanfile.py declares OpenSSL as a dependency:

class MyPackageConan(ConanFile):
    # ...
    requires = ("openssl/1.1.1l", )

Solution:

Make sure that the project’s CMakeLists.txt contains these lines:

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

Typically, the way to do this is to use this code which is automatically generated by conan new:

        # This small hack might be useful to guarantee proper /MT /MD linkage
        # in MSVC if the packaged project doesn't have variables to set it
        # properly
        tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
                              '''PROJECT(HelloWorld)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')

in source() like this:

    def source(self):
        self.run("git clone https://github.com/conan-io/hello.git")
        # This small hack might be useful to guarantee proper /MT /MD linkage
        # in MSVC if the packaged project doesn't have variables to set it
        # properly
        tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
                              '''PROJECT(HelloWorld)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')

Note that you need to replace both hello/CMakeLists.txt with the correct filename (typically, just replace hello by). Also, you need to replace both instances PROJECT(HelloWorld) by the actual line from your CMakeLists.txt in order for the replace command to work.

Posted by Uli Köhler in C/C++, CMake, Conan

How to add build-only dependencies in Conan recipe

Just add build_requires = ('dep1/version1', 'dep1/version2') to your conanfile.py:

class MyPackageConan(ConanFile):
    # ...
    requires = ("openssl/1.1.1l", )
    build_requires = ("jsoncpp/1.9.4", )

 

Posted by Uli Köhler in C/C++, Conan

How to run ‘git submodule update’ in Conan recipe

If you want to run git submodule update in your conanfile.py, you can simple add a self.run() command after the git clone command:

self.run("git clone https://github.com/conan-io/hello.git")
self.run("cd hello && git submodule update --init --recursive")

Full example:

self.run("git clone https://github.com/seznam/elasticlient.git -b version-0.2")
self.run("cd elasticlient && git submodule update --init --recursive")

Note that you need to cd <directory> && git submodule update

Posted by Uli Köhler in C/C++, Conan

How to add conan CMake build definition

When building a library using conan, this is the default conanfile.py definition for building using CMake

cmake = CMake(self)
cmake.configure(source_folder="hello")
cmake.build()

You can easily add definitions like this:

cmake.definitions["MY_FLAG"] = "1"

This will generate -DMY_FLAG=1 when calling CMake

Full example:

cmake = CMake(self)
cmake.definitions["USE_SYSTEM_CPR"] = "1
cmake.configure(source_folder="elasticlient")"
cmake.build()

Note that you need to add all cmake.definitions calls before calling cmake.configure()

Posted by Uli Köhler in C/C++, Conan

How to fix CMake Protobuf “FindThreads only works if either C or CXX language is enabled”

Problem:

When trying to configure your CMake project using

find_package(Protobuf REQUIRED)

you see an error message like

CMake Error at /usr/share/cmake-3.16/Modules/FindThreads.cmake:49 (message):
  FindThreads only works if either C or CXX language is enabled
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:420 (find_package)
  CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!

Solution:

You need to put your

project(MyProject)

line before the

find_package(Protobuf REQUIRED)

line. If you don’t have a project() line, create one.

Posted by Uli Köhler in C/C++, CMake

How to reload import in Jupyter

import mymodule
# Reload .py file every time we run the cell
from importlib import reload
reload(mymodule)

 

Posted by Uli Köhler in Python

How to read last byte from file in C++

Use fseek() with offset -1 and mode SEEK_END:

fseek(myfile, -1, SEEK_END);

Ready-to-use function

#include <cstdio>
#include <optional>

/**
 * Read the last byte of a given 
 */
std::optional<char> readLastByteOfFile(const char* filename) {
    FILE* fin = fopen(filename, "r");
    if(fin == nullptr) {
        return std::nullopt;
    }
    fseek(fin, -1, SEEK_END);
    char lastByte;
    if(fread(&lastByte, 1, 1, fin) == 0) {
        return std::nullopt;
    }
    fclose(fin);
    return lastByte;
}

Complete example program

#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <optional>

/**
 * Read the last byte of a given 
 */
std::optional<char> readLastByteOfFile(const char* filename) {
    FILE* fin = fopen(filename, "r");
    if(fin == nullptr) {
        return std::nullopt;
    }
    fseek(fin, -1, SEEK_END);
    char lastByte;
    if(fread(&lastByte, 1, 1, fin) == 0) {
        return std::nullopt;
    }
    fclose(fin);
    return lastByte;
}

int main(int argc, char** argv) {
    if(argc < 2) {
        std::cerr << "Usage: " << argv[0] << " <input file to read from>" << std::endl;
    }

    auto lastByte = readLastByteOfFile(argv[1]);
    if(lastByte) {
        std::cout << lastByte.value() << std::endl;
    } else {
        std::cout << "File error or empty" << std::endl;
    }
}

Generate test data with:

echo -n "abcd" > test.txt
touch test2.txt

Compile using:

g++ -o read-last-byte read-last-byte.cpp --std=c++17

Test using:

$ ./test-last-byte test1.txt
d
$ ./test-last-byte test2.txt
File error or no last byte
Posted by Uli Köhler in C/C++

How to pass flags to RapidXML xml_document::parse()

Use the template argument (<>) like this:

doc.parse<rapidxml::parse_non_destructive>(data);

Full example:

// Create & parse document
xml_document<> doc;
try {
    doc.parse<rapidxml::parse_non_destructive>(data);
} catch(rapidxml::parse_error& ex) {
    cerr << "XML Parse error in " << filename << endl; 
    return;
}

 

Posted by Uli Köhler in C/C++

How to autoscale matplotlib X&Y axis after set_data() call

After calling set_data() or set_ydata() in matplotlib the axis scale is not updated automatically. Use

ax.relim()
ax.autoscale_view(True,True,True)

to update both the X and the Y scale.

Full example:

line.set_data(x, y)
# Autoscale view
ax.relim()
ax.autoscale_view(True,True,True)
# Redraw
figure.canvas.draw()
figure.canvas.flush_events()

 

Posted by Uli Köhler in Python

How to fix pip cartopy error: “geos_c.h: No such file or directory”

Problem:

When trying to install cartopy on Linux using e.g. sudo pip3 install cartopy, you see an error message like

lib/cartopy/trace.cpp:633:10: fatal error: geos_c.h: Datei oder Verzeichnis nicht gefunden                                                                                                 
  633 | #include "geos_c.h"                                                                                                                                                                
      |          ^~~~~~~~~~                                                                                                                                                                
compilation terminated.                                                                                                                                                                    
setup.py:117: UserWarning: Unable to determine GEOS version. Ensure you have 3.3.3 or later installed, or installation may fail.

Solution:

Install libgeos-dev using

sudo apt -y install libgeos-dev

 

Posted by Uli Köhler in Cartopy, Python

How I fixed Python OSError: [Errno 99] Cannot assign requested address

Problem:

When binding a socket, you see an error message like

Traceback (most recent call last):
  File "run.py", line 91, in <module>
    server = start_server(loop, ('192.168.1.100', 8080))
  File "run.py", line 86, in start_server
    transport, server = loop.run_until_complete(t)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1332, in create_datagram_endpoint
    raise exceptions[0]
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1316, in create_datagram_endpoint
    sock.bind(local_address)
OSError: [Errno 99] Cannot assign requested address

Solution:

In my case, the issue was that I was trying to bind the specific IP address 192.168.1.100 but the computer running the script did not have said IP address configured on any interface.

server = start_server(loop, ('192.168.1.100', 8080))

so I needed to change the bind IP address to either 0.0.0.0 to listen to ANY IP address or I needed to change 192.168.1.100 to the IP address of the host computer I am running the script on.

Docker container [Errno 99] Cannot assign requested address

Note that for Docker containers, either you need to run them in network_mode: host to use the host’s network systemd, or you need to bind to the container’s IP address. You can not bind to the host’s IP address from the contaienr unless using network_mode: host! But you can forward the ports from the host, binding to a specific IP address.

Posted by Uli Köhler in Python

Python raw TCP client minimal example & cheatsheet

import socket

try:
    # Initialize socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("192.168.238.1", 12345))
    
    # Example: Send
    sock.send(b"abc123abc")

    # Example: Receive with timeout
    sock.settimeout(0.1)
    data = sock.recv(2048)
finally:
    sock.close()

 

Posted by Uli Köhler in Networking, Python

How to set log level for structlog

You can set the structlog log level by using the logging module:

import logging

# Example 1:
logging.getLogger().setLevel(logging.DEBUG)

# Example 2:
logging.getLogger().setLevel(logging.INFO)

 

Posted by Uli Köhler in Python