Symbol not found using dlopen in Python

Question:

I compiled BlockSci in macOS High Sierra 10.13.6. This created /usr/local/lib/libblocksci.dylib. I used pip3 to install the blocksci Python analysis library and this created /Users/${USER}/dev/BlockSci/blockscipy/blocksci/_blocksci.cpython-39-darwin.so.

When I try to import the library via $ python3 hello.py:

import blocksci

It creates the following error in dlopen due to a symbol not found:

Traceback (most recent call last):
  File "/Users/${USER}/dev/BlockSci/hello.py", line 1, in <module>
    import blocksci
  File "/Users/${USER}/dev/BlockSci/blockscipy/blocksci/__init__.py", line 29, in <module>
    from ._blocksci import *
ImportError: dlopen(/Users/${USER}/dev/BlockSci/blockscipy/blocksci/_blocksci.cpython-39-darwin.so, 2): Symbol not found: __ZN8blocksci10heuristics16getPoisonTaintedERSt6vectorINS_6OutputESaIS2_EEib
  Referenced from: /Users/${USER}/dev/BlockSci/blockscipy/blocksci/_blocksci.cpython-39-darwin.so
  Expected in: flat namespace
 in /Users/${USER}/dev/BlockSci/blockscipy/blocksci/_blocksci.cpython-39-darwin.so

I found this and this to be informative but I can’t determine how to fix this so I can interact with the C++ library.

Finally, pip3 list returns:

Package               Version     Editable project location
--------------------- ----------- ----------------------------------------
astroid               2.5
blocksci              0.7.0       /Users/${USER}/dev/BlockSci/blockscipy
certifi               2021.10.8
...
Asked By: Hahnemann

||

Answers:

I found the problem. I was mixing compilers, using clang for the BlockSci code and gcc in pybind11 to bind the C++ code with Python.

Answered By: Hahnemann