-
I am simply trying to get the code from https://github.com/daknuett/extension-cpp-meson to install to site_packages and run. It builds and installs but can't resolve symbols when I try to import extension_cpp. Using ldd shows:
Both libc10.so and libtorch_cpu.so are available in .venv/lib/python3.13/site-packages/torch/lib
How do I change meson.build so that _C.cpython-313-x86_64-linux-gnu.so contains the correct path for libc10.so and libtorch_cpu.so? PS: The unresolved symbol is the same one as in this discussion: |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 17 replies
-
Broadly speaking, this is impossible for library technology to do in the first place. libtorch_cpu.so etc can be in any directory, because pytorch itself could be installed to any site-packages directory in You need indirection for this, in the form of e.g. capsule imports, but that assumes that the project in question (pytorch, here) supports such usage. The other approach to this is that your extension is "broken" by default but works when imported by a python module that first dynamically computes the search path and then sets things up. I don't know what pytorch users usually do (I don't use pytorch myself). It's possible that some solutions might be "good enough", e.g. hardcoding the absolute path on the build machine, which means all users must compile their own copy of the package. You could also assume that people don't install to multiple sys.path directories (they actually do, but maybe the users of any given package don't) and simply hardcode an rpath of Does pytorch not provide any guidance for this? |
Beta Was this translation helpful? Give feedback.
-
Quick question: how did you set up your environment and built |
Beta Was this translation helpful? Give feedback.
-
I did a clean install again and tried with the following change to meson.build.
It still produces the same unresolved symbol error. I hard-coded cxx11abi to 0. It resulted in the same error. |
Beta Was this translation helpful? Give feedback.
-
I am using python-3.13, g++-13 on ubuntu-24.04 (through WSL2). Torch version is 2.7.1. |
Beta Was this translation helpful? Give feedback.
-
I added 'cuda' to the project like so:
Then, I added the cuda source to the list of sources passed to python.extension_module, like so:
Now all 8 tests pass. |
Beta Was this translation helpful? Give feedback.
Turns out I didn't need to use cpp_args or add_project_arguments(). But I needed to add the following to the meson.build that @daknuett has.
Now, nm produces what I have been seeking: