indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.71k stars 107 forks source link

Undefined symbols when linking against libpython static library #166

Open jorgschulze73 opened 1 year ago

jorgschulze73 commented 1 year ago

I'm trying to embed Python interpreter in a C++ application with no external dependencies and found this project. I downloaded latest install-only prebuilt assets for arm64 macOS but when trying to compile my app against libpython3.11d.a I receive a lot of errors about undefined symbols (mostly from OpenSSL):

Undefined symbols for architecture arm64:
  "_ASN1_OBJECT_free", referenced from:
      __ssl_txt2obj in libpython3.11d.a(_ssl.o)
      __ssl_nid2obj in libpython3.11d.a(_ssl.o)
  "_ASN1_OCTET_STRING_free", referenced from:
      _newPySSLSocket in libpython3.11d.a(_ssl.o)
  "_ASN1_STRING_get0_data", referenced from:
      __create_tuple_for_X509_NAME in libpython3.11d.a(_ssl.o)
      __get_peer_alt_names in libpython3.11d.a(_ssl.o)
      _newPySSLSocket in libpython3.11d.a(_ssl.o)
  "_ASN1_STRING_length", referenced from:
      __create_tuple_for_X509_NAME in libpython3.11d.a(_ssl.o)
      __get_peer_alt_names in libpython3.11d.a(_ssl.o)
      _newPySSLSocket in libpython3.11d.a(_ssl.o)
  "_ASN1_STRING_to_UTF8", referenced from:
      __create_tuple_for_X509_NAME in libpython3.11d.a(_ssl.o)
  "_ASN1_STRING_type", referenced from:
      __create_tuple_for_X509_NAME in libpython3.11d.a(_ssl.o)
  "_ASN1_TIME_print", referenced from:
      __decode_certificate in libpython3.11d.a(_ssl.o)
  "_AUTHORITY_INFO_ACCESS_free", referenced from:
      __get_aia_uri in libpython3.11d.a(_ssl.o)
  "_BIO_clear_flags", referenced from:
      __ssl_MemoryBIO_write_eof in libpython3.11d.a(_ssl.o)
  "_BIO_ctrl", referenced from:
      __ssl__test_decode_cert in libpython3.11d.a(_ssl.o)
      __decode_certificate in libpython3.11d.a(_ssl.o)
      __get_peer_alt_names in libpython3.11d.a(_ssl.o)
      _newPySSLSocket in libpython3.11d.a(_ssl.o)
      __PySSLContext_set_keylog_filename in libpython3.11d.a(_ssl.o)
      __PySSL_keylog_callback in libpython3.11d.a(_ssl.o)
      __ssl__SSLSocket_do_handshake in libpython3.11d.a(_ssl.o)
      ...

Is this supposed to be intended behaviour? If yes, where can I found the prebuilt assets for OpenSSL (and other required dependencies) so that I can link against those as well?

indygreg commented 4 months ago

This might be a bug in our build system.

The libpython.a static libraries may only have the libpython symbols and not all the other libraries that are linked into libpython.dylib. As a workaround, the full zstandard compressed distributions have all the raw object files and static archive inputs used to produce the installable Python distribution. In the case of these macOS distributions, you should be able to link against python/build/lib/libcrypto.a and python/build/lib/libssl.a to pull in the missing symbols.

Although I'm wondering if this is a symbol visibility problem. This may be one of the subtle problems that goes away if we just distribute shared libraries for 3rd party dependencies instead of aggressively statically linking everything.