libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
532 stars 304 forks source link

Cython bindings fail to compile with version 3.9 due to libintl #196

Closed rickmark closed 2 years ago

rickmark commented 2 years ago

This is an issue I've seen before, but just making an issue to track before correcting it.

Somewhere along the way Python broke out some internationalization components from libpython and when using Autotools you must ensure you link to all the libraries that Cython tells you to, not just -lpython now. For discoverability the error looks like this:

make[2]: Nothing to be done for `all'.
Making all in cython
/Users/rickmark/.pyenv/shims/cython -I. -I../src -o plist.c plist.pyx
/Users/rickmark/.pyenv/versions/3.9.6/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /Users/rickmark/Developer/libplist/cython/plist.pxd
  tree = Parsing.p_module(s, pxd, full_module_name)
/Library/Developer/CommandLineTools/usr/bin/make  all-am
  CC       plist_la-plist_util.lo
  CC       plist_la-plist.lo
  CCLD     plist.la
Undefined symbols for architecture x86_64:
  "_libintl_bind_textdomain_codeset", referenced from:
      _PyIntl_bind_textdomain_codeset in libpython3.9.a(_localemodule.o)
  "_libintl_bindtextdomain", referenced from:
      _PyIntl_bindtextdomain in libpython3.9.a(_localemodule.o)
  "_libintl_dcgettext", referenced from:
      _PyIntl_dcgettext in libpython3.9.a(_localemodule.o)
  "_libintl_dgettext", referenced from:
      _PyIntl_dgettext in libpython3.9.a(_localemodule.o)
  "_libintl_gettext", referenced from:
      _PyIntl_gettext in libpython3.9.a(_localemodule.o)
  "_libintl_setlocale", referenced from:
      _PyLocale_setlocale in libpython3.9.a(_localemodule.o)
      _PyLocale_localeconv in libpython3.9.a(_localemodule.o)
  "_libintl_textdomain", referenced from:
      _PyIntl_textdomain in libpython3.9.a(_localemodule.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Fix will be applied by changing the import definition for the link stage of build.

rickmark commented 2 years ago

So - I kinda think this is a python bug, because it seems wrong for every library that depends on libpython to have to depend on libintl. Will file the bug but in the interim adding PYTHON_EXTRA_LIBS will bring in the libintl dependency.

Man what a day for top-posting 😅

Yeah correct answer wrong reason. This occurs because for some reason we try to compile the Cython module as a static library. Static libraries are required to be fully resolved.

The REAL answer is to not compile a static library version as the Cython module cannot exist without Python. If we really want a static library, you can use the embedding linkage, but it seems very odd that one would load the Cython module without having a python environment first.

nikias commented 2 years ago

Merged #197.