Embedding Python in C, linking fails with undefined reference to `Py_Initialize'

前端 未结 5 1509
陌清茗
陌清茗 2021-02-14 02:21

I am trying to compile the example from the docs https://docs.python.org/2.7/extending/embedding.html and my code looks exactly like the one under 5.1:

#include          


        
5条回答
  •  孤城傲影
    2021-02-14 03:06

    The accepted answer uses system's default library location.

    If you are within an anaconda environment, library location may not be found. I tend to give locations more explicitly during linking, like:

    gcc embedpy.o -L$(python-config --prefix)/lib $(python-config --ldflags)
    

    This will not work outside anaconda environment in 64-bit library, in which case:

    gcc embedpy.o -L$(python-config --prefix)/lib64 $(python-config --ldflags)
    

提交回复
热议问题