How do I compile a shared library to be used with ctypes on mesonpy? #573
-
Hello. Suppose I have pip-installed meson, mesonpy and ninja. I have a project structured like this:
With the following
I can build a file Obviously having to compile the shared library directly sucks, and I'd like the user to just How am I supposed to do this with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You need a Python package to make
To do that, you need something like this: py = import('python').find_installation(pure: false)
py.install_sources(
['source/wrapper.py'],
subdir: 'mypkg'
)
shared_library('mylib'
['source/mylib.c'],
include_directories : ['source/include'],
install: true,
install_dir: py.get_install_dir() / 'mypkg',
) The |
Beta Was this translation helpful? Give feedback.
-
dear Ralf and Daniele, thank you very much for your help, I truly appreciate. (testenv) peppedilillo@pepbook meson-test % pip install .
Processing /Users/peppedilillo/Library/CloudStorage/Dropbox/Progetti/meson-test
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mypkg
Building wheel for mypkg (pyproject.toml) ... done
Created wheel for mypkg: filename=mypkg-0.0.1-cp311-cp311-macosx_13_0_arm64.whl size=3841 sha256=37c69cd5d2b53c49a0470730fc04be4c3d2ce130dc36e66dd6cce4610a118b64
Stored in directory: /Users/peppedilillo/Library/Caches/pip/wheels/2e/c7/6c/98b3ab681413a1de05be5bda2122cd94f19923c3e95b1b66e2
Successfully built mypkg
Installing collected packages: mypkg
Attempting uninstall: mypkg
Found existing installation: mypkg 0.0.1
Uninstalling mypkg-0.0.1:
Successfully uninstalled mypkg-0.0.1
Successfully installed mypkg-0.0.1 However I can't find the shared library where I'm expecting it to be, i.e. in the directory My
Thank you once again. Not only you are making a lot of science possible with numpy, scipy, meson-python and the alike.. You are giving many scientists something to be passionated about!!! Bests. |
Beta Was this translation helpful? Give feedback.
You'll want to look into how regular Python packages work. You should have
wrapper.py
and an__init__.py
right next to your shared library if you install to site-packages. And then you use it via animport
statement, not via runningpython wrapper.py
.