Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking python extensions against libpython is broken #7712

Closed
tschoonj opened this issue Sep 9, 2020 · 3 comments
Closed

Linking python extensions against libpython is broken #7712

tschoonj opened this issue Sep 9, 2020 · 3 comments

Comments

@tschoonj
Copy link
Contributor

tschoonj commented Sep 9, 2020

Describe the bug

Meson has been able to detect for some time if python extensions should be linked against libpython or not. However, this only works if python was found as a PythonDependency and not as as PkgConfigDependency.

The problem in the code is here:

# On macOS and some Linux distros (Debian) distutils doesn't link
# extensions against libpython. We call into distutils and mirror its
# behavior. See https://github.com/mesonbuild/meson/issues/4117
if not self.link_libpython:
new_deps = []
for holder in mesonlib.extract_as_list(kwargs, 'dependencies'):
dep = holder.held_object
if isinstance(dep, PythonDependency):
holder = self.interpreter.holderify(dep.get_partial_dependency(compile_args=True))
new_deps.append(holder)
kwargs['dependencies'] = new_deps

This obviously doesn't work when I add a print statement dumping the dependencies:

new_deps=[<Holder: <PkgConfigDependency gstreamer-1.0: True ['>= 1.18.0']>>, <Holder: <PkgConfigDependency python-3.8-embed: True ['>=3']>>, <Holder: <PkgConfigDependency pygobject-3.0: True ['>= 3.8']>>]

To Reproduce
Just try building a Python extension against a python that ships pkg-config files: the resulting binary will always be linked against libpython.

Expected behavior
Linking against libpython should also work when python was detected through its pkg-config file.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) macOS Catalina
  • what Python version are you using e.g. 3.8.0: 3.8, installed with homebrew
  • what meson --version: 0.55.1
  • what ninja --version if it's a Ninja build: 1.10.1

@nirbheek @lazka

@lazka
Copy link
Contributor

lazka commented Sep 9, 2020

Python has two pkg-config files, one or extensions, one for embedding:

> pkg-config --libs python3

> pkg-config --libs python3-embed
-lpython3.8

If you build an extension you should use python3 which doesn't link.

@tschoonj
Copy link
Contributor Author

tschoonj commented Sep 9, 2020

The project that is causing problems is gst-python.

There are two plugins being built there, and they seem to enforce using the embedded python for both, while I think only one of them (the Gst python plugin) needs it. The other one is a PyGobject module, so should be fine without it.

What do you think @lazka ?

Either way, clearly not a bug in Meson, so closing.

@tschoonj tschoonj closed this as completed Sep 9, 2020
@lazka
Copy link
Contributor

lazka commented Sep 9, 2020

What do you think @lazka ?

I think your assessment is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants