Is this Boost::Python (Python 3.7) error “__init__() should return None, not 'NoneType'” a linking problem?

后端 未结 2 520
终归单人心
终归单人心 2021-01-20 18:01

Update

I\'m not going to add this as an answer, since I still haven\'t technically solved the problem. But since I\'ve now spent 2.5 days trying to get things to w

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 18:28

    Adding an answer here for those using the Anaconda or Conda-Forge Distribution:

    The python interpreter statically links in the libpythonXY library. Which is why it makes the python binary different compared to other distributions.

    The fix for the problem reported by OP is to use:

    -undefined dynamic_lookup
    

    Instead of:

    -lpythonXY
    

    You are creating a Python C/C++ extension, and not embedding the python interpreter. So you shouldn't be linking to the python library. Pybind11 handles this correctly.

    See the following for more information:

    • https://gitlab.kitware.com/cmake/cmake/issues/18100
    • https://github.com/ContinuumIO/anaconda-issues/issues/9078

    One a side note, python 3.8 has added an additional flag: --embed and only then it adds -lpythonXY in the output:

    $ python3.8-config --libs
    -ldl -framework CoreFoundation
    
    $ python3.8-config --libs --embed
    -lpython3.8 -ldl -framework CoreFoundation
    

提交回复
热议问题