我试图从 C 代码中调用 python 函数,我遵循了一个示例 from here
我也有正确的包含文件目录、库目录,并链接了 python32.lib(我使用 python 32)但是错误是 python/C API,如 PyString_FromString、PyInt_FromLong、PyInt_AsLong 未定义(调试器中的错误)
这很奇怪,因为我也在使用其他 API,但它们都很好......
这里有什么问题??
int
main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
int i;
if (argc < 3) {
fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
return 1;
}
Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
pDict = PyModule_GetDict(pModule);
/* pDict is a borrowed reference */
Py_Initialize()、PyImport_Import()、PyModule_GetDict() 都可以正常工作,但 PyString_FromString 不行...