我正在尝试编译一个可以使用nvcc从python调用的库。通常在Windows上我使用msys / mingw工具链,可以编译python扩展没有问题。但是,当我尝试使用nvcc进行编译时,我相信它使用的是link.exe(Microsoft Visual Studio的一部分)。虽然它编译得很好,但它在链接步骤失败了。
我意识到我正在使用旧版本的python(2.5版)。我正在使用遗留应用程序,我暂时坚持使用旧版本。
这是我正在尝试的nvcc命令:
nvcc -I "C:\Python25\include" -I "C:\python25\Lib\site-packages\numpy\core\include\numpy" -L "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\x64" -lcusolver -lcusparse -Xlinker "C:\Python25\libs\python25.lib" cusolve5.cu
但它失败了这条消息:
Creating library a.lib and object a.exp
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyObject_GetAttrString referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyCObject_AsVoidPtr referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_SetString referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_Format referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyArg_ParseTuple referenced in function main
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_Py_BuildValue referenced in function main
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function "void __cdecl initbmc(void)" (?initbmc@@YAXXZ)
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyErr_Print referenced in function "void __cdecl initbmc(void)" (?initbmc@@YAXXZ)
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyImport_ImportModule referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyCObject_Type referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_AttributeError referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_ImportError referenced in function _import_array
tmpxft_00001128_00000000-28_cusolve5.obj : error LNK2019: unresolved external symbol __imp_PyExc_RuntimeError referenced in function _import_array
a.exe : fatal error LNK1120: 13 unresolved externals
在我看来,找不到python库。使用msys / mingw,我可以像这样链接一个类似的库:
g++ bmc.o -L "/c/python25/libs" -lpython25 -shared -o bmc.pyd
工作正常(但不包括我正在处理的任何GPU加速)。我的猜测是我需要通过-Xlinker命令传递link.exe,但我似乎找不到在构建时包含python库的方法。
答案 0 :(得分:1)
感谢来自@talonmies的提示,我得出的结论是,我想要做的事情是不可能的,原因有两个:
但是,通过使用ctypes加载dll而不是标准的python导入,可以解决这个问题。然而...