#include <Python.h>
static PyObject* helloworld(PyObject* self)
{
return Py_BuildValue("s", "Hello, Python extensions!!");
}
static char helloworld_docs[] =
"helloworld(): Any message you want to put here!!\n";
static PyMethodDef helloworld_funcs[] = {
{"helloworld", (PyCFunction)helloworld,
METH_NOARGS, helloworld_docs},
{NULL}
};
void inithelloworld(void)
{
Py_InitModule3("helloworld", helloworld_funcs,
"Extension module example!");
}
我一直在試圖用C擴展Python,因此一直試圖在Visual Studio中編譯上面的代碼。不過,我反覆出現以下錯誤:試圖從C調用Python
HiWorld.obj : error LNK2001: unresolved external symbol __imp__Py_BuildValue
HiWorld.obj : error LNK2001: unresolved external symbol __imp__Py_InitModule4
我一直停留在這個很長一段時間,並會:
LINK : fatal error LNK1104: cannot open file 'python27.lib'
添加python27.lib的項目,然後我收到以下錯誤後非常感謝任何建議。