我需要创建一个新的python模块,作为性能和CUDA利用率的c扩展。我试过几个教程,但没有成功。以下是我的档案:
hellomodule.c#include
static PyObject* say_hello(PyObject* self, PyObject* args)
{
const char* name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
printf("Hello %s!\n", name);
Py_RETURN_NONE;
}
static PyMethodDef HelloMethods[] =
{
{"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC inithello(void)
{
(void) Py_InitModule("hello", HelloMethods);
}
设置hello.py
^{pr2}$
这是我对python setuphello.py build的结果:running build
running build_ext
building 'hello' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Anaconda3\include -IC:\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" "-IC:\Program Files (x86)\IntelSWTools\Trace Analyzer and Collector\9.1.2.024\include" /Tchellomodule.c /Fobuild\temp.win32-3.5\Release\hellomodule.obj
hellomodule.c
hellomodule.c(23): warning C4013: 'Py_InitModule' undefined; assuming extern returning int
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Anaconda3\libs /LIBPATH:C:\Anaconda3\PCbuild\win32 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\um\x86" /EXPORT:PyInit_hello build\temp.win32-3.5\Release\hellomodule.obj /OUT:build\lib.win32-3.5\hello.cp35-win32.pyd /IMPLIB:build\temp.win32-3.5\Release\hello.cp35-win32.lib
LINK : error LNK2001: unresolved external symbol PyInit_hello
build\temp.win32-3.5\Release\hello.cp35-win32.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\link.exe' failed with exit status 1120
我已经看过其他人犯过的各种错误,并试图遵循他们的调试逻辑,但老实说,对于导致我的错误的幕后发生的事情,我感到茫然。我使用Python 3.5 32位(ANACODA),所以一直尝试用VisualC++构建工具和它的打包终端编译。不过,这没有任何区别。有人能把我引向正确的方向吗?在