【发布时间】:2014-05-17 00:57:21
【问题描述】:
我正在尝试使用 C++ 中的嵌入式解释器运行一些 python 命令(我正在使用 Marmalade 中间件并编译为 arm;这是编译到库的 python 2.6.4 的移植版本;我正在链接到库并加载到移植的python头文件中)
[此处完全移植的代码:https://github.com/marmalade/python]
我的问题是我不知道如何正确导入函数,我不断收到 PyRun_SimpleString 的“类型说明符”错误
我应该将其指定为 void 而不是 int 还是与 PyAPI_FUNC(int) 有其他关系?
PythonTest.cpp(使用 libpython_d.a)
#include "Python.h"
extern int PyRun_SimpleString(const char*);
extern void Py_Initialize(void);
extern void Py_Finalize(void);
int main() {
while(true){
Py_Initialize();
PyRun_SimpleString("print('Python Print test')");
Py_Finalize();
}
return 0;
}
error:
PythonTest.cpp(3): error : expected identifier before '__null' (col 48)
PythonTest.cpp(3): error : expected ',' or '...' before '__null' (col 48)
IntelliSense: expected a type specifier PythonTest.cpp 3
这些是引用 PyRun_SimpleString 函数和一些相关依赖项的摘录。 [在 libpython_.a 中编译;头目录已链接]
pythonrun.h
#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
...
...
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
pythonrun.c
#undef PyRun_SimpleString
PyAPI_FUNC(int)
PyRun_SimpleString(const char *s)
{
return PyRun_SimpleStringFlags(s, NULL);
}
pyport.h
#ifndef PyAPI_FUNC
# define PyAPI_FUNC(RTYPE) RTYPE
【问题讨论】:
-
我正在尝试做的工作示例Pastebin-Marmalade library example
标签: python c++ visual-studio types marmalade