kilojoules kilojoules - 1 year ago 110
C++ Question

What does "Symbol not found / Expected in: flat namespace" actually mean?

When I import a module I built, I get this boost-python related error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(./, 2): Symbol not found: __ZN5boost6python7objects15function_objectERKNS1_11py_functionERKSt4pairIPKNS0_6detail7keywordES9_E
Referenced from: ./
Expected in: flat namespace
in ./

What does this actually mean? Why was this error raised?

Answer Source


The problem caused by mixing objects that compiled with libc++ and object that compiled with libstdc++.

In our case, the library (compiled with libstdc++) need boost-python that compiled with libstdc++ (boost-python-libstdc++ from now). When boost-python is boost-python-libstdc++, it will work fine. Otherwise - on computer that its boost-python has compiled with libc++ (or another c++ library), it will have a problem loading and running it.

In our case, it happens because that libc++ developers intentionally changed the name of all of their symbols to prevent you (and save you) from mixing code from their library and code from a different one: need a function that take an argument from the type. In libc++, this type's name is std::__1::pair. Therefore, this symbol was not found.

To understand why mixing two version of the same API is bad, consider this situation: There are too libraries: Foo and Bar. They both has a function that take a std::string and use it for something but they use a different c++ library. When a std::string that has been created by Foo will be passed to Bar, Bar will think that this is an instance of its c++ library's std::string and then bad things can happen (they are a completely different objects).

Note: There is no problem with two or more different versions of the same API in a completely different parts of a program. There will be a problem if they will pass this API's objects between them. However, checking that can be very hard, especially if they pass the API object only as a member of another object.

How to solve that?

  • You can always recompile your libraries and make them match each other.

  • You can link boost-python to your library as a static library. Then, it will work on almost every computer (even one that doesn't has boost-python installed). See more about that here.

Summary need another version of boost-python, one that compiled with a specific c++ library. Therefore, It would not work with any another version.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download