【问题标题】:Error while embedding Python in a C++ application: undefined reference to `_imp__Py_Initialize'在 C++ 应用程序中嵌入 Python 时出错:未定义对 `_imp__Py_Initialize' 的引用
【发布时间】:2022-07-22 16:44:36
【问题描述】:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdio.h>
#include <conio.h>



int main()
{
    char filename[] = "quickstart.py";
    FILE* fp;

    Py_Initialize();

    fp = fopen(filename, "r");
    PyRun_SimpleFile(fp, filename);

    Py_Finalize();
    return 0;
}

我想将 python 脚本嵌入到我的 c++ 应用程序中,我还添加了 Python\Python310\include 和 Python\Python310\Lib 到 Dev-c++ 的路径,但我仍然收到此错误

main.cpp:(.text+0x38): undefined reference to `_imp__Py_Initialize'
main.cpp:(.text+0x76): undefined reference to `_imp__PyRun_SimpleFileExFlags'
main.cpp:(.text+0x7d): undefined reference to `_imp__Py_Finalize'
[Error] ld returned 1 exit status

【问题讨论】:

  • 帮自己一个忙,切换到比 Dev-C++ 更新的 IDE,它已经有 20 年没有真正更新了。我推荐 Qt Creator,它会更有帮助,并且支持现代构建系统。

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


【解决方案1】:

您需要链接 Python 库,而不仅仅是添加路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-31
    • 2014-02-12
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多