Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined Symbol: _ZN3a13A when importing pybind11 bindings

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.

like image 870
Armin Meisterhirn Avatar asked Nov 30 '18 20:11

Armin Meisterhirn


1 Answers

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.

like image 195
2 revs, 2 users 89% Avatar answered Oct 15 '22 23:10

2 revs, 2 users 89%