Issue
I'm trying to create pybind11 bindings for an existing cmake project. The CMakeLists.txt
file looks like the one in the tutorial. The project builds without errors, however, when trying to import the module in ipython, the following error comes up:
~/workspace/a/build/pya.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZN3a13FooC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Trying to solve it: It seems related to the toolchain (this issue looks similar). I've gcc 6.5.0 and cmake 3.12.0 installed.
Solution
This is harder to answer than necessary, the linker error message is obfuscated. Use an online demangler to see the plaintext symbol name that the linker cannot find. Be sure to copy/paste the real mangled symbol.
A valid mangled name that somewhat resembles the error message would be _ZN1a3FooC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
. Which demangles to a::Foo::Foo(const std::string&)
.
In other words, you declared a constructor for the Foo class but forgot to write it. Pretty standard mistake. More about these linker errors in this Q+A.
Answered By - Hans Passant
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.