jamesbowman / openexrpython

OpenEXR bindings for Python
Other
94 stars 35 forks source link

Linker error when importing #26

Open ShnitzelKiller opened 5 years ago

ShnitzelKiller commented 5 years ago

When I attempt to import this package (tried different python versions, no difference), I get the following error:

import OpenEXR

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /local1/jamesn8/anaconda3/envs/exrtest/lib/python3.5/site-packages/OpenEXR.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZNK3Imf14TypedAttributeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE12writeValueToERNS_7OStreamEi

I'm running linux, but this is an identical issue to https://github.com/openexr/openexr/issues/207 which pertains to the OSX version. See that thread for more info . The exact undefined symbol is the same as described in the post by jbartolozzi. I'm just opening the issue here in case it can be better addressed as a problem with the binding library (if that's indeed what it is).

tiagoshibata commented 5 years ago

You can use a demangler (such as https://demangler.com/) to demangle the C++ symbol. It resolves to Imf::TypedAttribute<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::writeValueTo(Imf::OStream&, int) const.

If I'm not mistaken it should resolve to a symbol in the OpenEXR library. Is it installed and available in your dynamic linker path? If you compiled the C++ library from source, try setting LD_LIBRARY_PATH to the folder containing it.

tiagoshibata commented 5 years ago

Another possibility is that you compiled the C++ library and the Python bindings with incompatible flags. GCC had ABI changes for C++11 (see this stack overflow post). You might have a recent version of GCC installed and an old version of the library, which was compiled with an older GCC release.

If my previous answer did not help, try listing the symbols in the library and check if the missing one is available. Check if the exact signature matches (including the __cxx11 namespace in basic_string). If not, recompile either of them (follow the instructions in the stack overflow page).


If none of this helps you, please give us more information about your system (distro, OpenEXR library version, where the library came from (system repository or local build), GCC version used to build the library and the bindings...)

jbartolozzi commented 5 years ago

Most likely an issue with anaconda using the latest OpenEXR libraries (2.3.x) This module seems to ship with 1.3x with pip

zkk0911 commented 5 years ago

HI ShnitzelKiller , I have the same issue, Have you addressed this problem @ShnitzelKiller

@tiagoshibata I have done nothing with the GCC. the openexr version is 1.3.2 installed with command "pip install OpenEXR"

tiagoshibata commented 5 years ago

I have done nothing with the GCC

Running pip install OpenEXR will download the sources for the Python bindings and compile them locally in your machine. If the OpenEXR library was compiled with the old C++ ABI and the OpenEXR bindings are compiled with the new one, it won't work.

If my previous answer did not help, try listing the symbols in the library and check if the missing one is available. Check if the exact signature matches (including the __cxx11 namespace in basic_string).

Did you try this? readelf -Ws /path/to/libIlmImf.so | grep writeValueTo should do it. If the symbol with the __cxx11 prefix is missing, compile the bindings with -D_GLIBCXX_USE_CXX11_ABI=0 (pass this flag to the package being compiled when you do pip install).

tiagoshibata commented 5 years ago

BTW, here's a more detailed and authoritative reference: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

If none of this helps you, please give us more information about your system (distro, OpenEXR library version, GCC version used to build the bindings...)

ShnitzelKiller commented 5 years ago

HI ShnitzelKiller , I have the same issue, Have you addressed this problem @ShnitzelKiller

@tiagoshibata I have done nothing with the GCC. the openexr version is 1.3.2 installed with command "pip install OpenEXR"

I ended up using OpenCV.