【发布时间】:2022-08-09 22:05:14
【问题描述】:
我在 c 中遇到了 python api 的问题。我正在尝试使用 PyRun_SimpleFile 运行 python 脚本,但它失败了
我收到此错误:d:/gcc/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\\Users\\aggel\\AppData\\Local\\Temp\\ccRzYgwa.o:pyboot.c:(.text+0x47): undefined reference to __imp_PyRun_SimpleFileExFlags\' collect2.exe: error: ld returned 1 exit status
编码:
define PY_SSIZE_T_CLEAN
#include <stdio.h>
#include <conio.h>
#include \"Python.h\"
#include \"fileapi.h\"
#include \"fileobject.h\"
int main(){
PyObject* pInt;
FILE *file = fopen( \"test.py\", \"r+\" );
PyRun_SimpleFile(file, \"test.py\");
return 0;
}
-
此错误意味着您需要链接定义
PyRun_SimpleFile的库(例如-lyourlibrary)。如果您需要更多帮助,则需要指定此函数的定义位置。
标签: python c python-c-api