-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Unable to build and use libtorch function via pybind11: undefined symbol error upon import #73016
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
Comments
The error message: Upon demangling looks as follows: Any thoughts on what might be wrong here? |
I was previously using the cxx11 ABI version of the libtorch package available on pytorch.org. Just for an experiment, I used the Pre-cxx11 ABI version and now I am getting the following error: Traceback (most recent call last):
File "../../../test.py", line 14, in <module>
main()
File "../../../test.py", line 10, in main
print(j.test(t1, t2))
TypeError: test(): incompatible function arguments. The following argument types are supported:
1. (arg0: at::Tensor, arg1: at::Tensor) -> at::Tensor
Invoked with: tensor([[0.4624, 0.3462],
[0.4250, 0.3891]]), tensor([[0.6797, 0.2709],
[0.5302, 0.7420]]) Is this error related to #20356? |
I guess currently cannot do this via CMAKE, but only via setuptools, which PyTorch has already included via cpp_extensions I am able to build the project now but cannot debug libtorch. |
I have a similar issue where |
Any update on this thread? Same issue here of missing |
Defining a macro named |
@anubane |
Running into the same problem as well, even when building torch using the same |
Yes, currently cpp_extension (setuptools) seems to be the only solution. |
Hello, is there still no other solution than this ? |
Having the absolute same issue, but only for CUDA extensions. |
Worked through my problem if this can help anyone: Check that anything you're trying to build with libtorch is built with the same c++ standard lib that libtorch was built with. Let me explain: So either build libtorch from source with your prefered compiler or build your project with the libstdc++ (gcc with c++11 standard and higher). |
https://github.com/r-barnes/pytorch_cmake_example This looks very interesting. |
It is, thank you. |
thanks! It was very helpful. In the conda env, I can build cpp extension successfully only when conda create -n dev-test -c conda-forge gcc=11.1 gxx=11.1 libstdcxx-ng=11.1 python=3.11 |
🐛 Describe the bug
I am attempting to write a C++ function in libtorch, compile it with pybind11 and then import the .so file in a python file.
The build seems to work fine (no errors are emitted) but, when I try to import it into my python file, execution fails with the error message:
ImportError: /home/cppNpython/MyProj/cpp/build/srcfile.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN3c106detail23torchInternalAssertFailEPKcS2_jS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
This is my directory structure:
Here are the contents of each file:-
srcfile.cpp
srcfile.h
CMakeLists.txt
and at last test.py
Inside the
build
directory I am executing the following command at the terminal:which does not emit any error.
I get the error only when I am attempting to import.
I am not sure what I am doing wrong here. Any help/suggestion is welcome.
Versions
cc @jbschlosser @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @VitalyFedyunin
The text was updated successfully, but these errors were encountered: