【问题标题】:Embedding Python: undefined reference to `_imp__Py_Initialize'嵌入 Python:未定义的对 `_imp__Py_Initialize' 的引用
【发布时间】:2018-09-10 20:00:41
【问题描述】:

我正在尝试将 python 3.7.0 嵌入到 C++ 应用程序中并使用 MinGW 进行编译。

#include "Dependencies/include/Python.h"


int main()
{

    PyObject* myPointer;
    Py_Initialize();
    return 0;
}

我用这个编译:

g++ ./TestEmbedding.cpp

我得到这个错误:

对 `_imp__Py_Initialize' 的未定义引用

【问题讨论】:

    标签: c++ python-3.x python-embedding


    【解决方案1】:

    编辑: 找到并回答:

    需要包含 python 库文件的路径。我个人现在正在使用 Visual Studio,只是将它包含在设置中,但我认为 MinGW 可以通过一些命令行调整来做到这一点。

    在库路径中包含与此类似的内容。 C:Local\Programs\Python\Python37\Lib

    【讨论】:

    • 我的本地文件夹中没有python文件夹。
    【解决方案2】:

    您需要使用 Python 标头进行构建:

    g++ TestEmbedding.cpp `python3-config --includes` -o TestEmbedding
    

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 2013-03-12
      • 2016-07-31
      • 2020-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多