And*_*ykh 8 c c++ python numpy visual-c++
我正在构建一个将调用python + numpy的C++应用程序,我想DELAYLOAD python dll.我在Windows上使用64位python 3.6的Visual Studio 2015.只要我不使用numpy,DELAYLOAD就可以正常工作.我打电话后import_array(),我再也无法使用DELAYLOAD选项进行构建.链接器错误是
由于导入数据符号'__imp_PyExc_ImportError',LNK1194无法延迟加载'python36.dll'; 没有/DELAYLOAD:python36.dll的链接.
这是我的代码:
// Initialize python
Py_Initialize();
// If I remove this line, I am able to build with DELAYLOAD
import_array();
Run Code Online (Sandbox Code Playgroud)
使用numpy时有没有办法让延迟加载?
替代问题:是否可以在不调用import_array()的情况下创建和填充numpy.recarray数据?
编辑:我决定摆脱import_array().以下是我用来初始化Python的一些代码:
if (!Py_IsInitialized())
{
// Initialize Python
Py_Initialize();
// Initialize threads
PyEval_InitThreads();
// Needed for datetime
PyDateTime_IMPORT;
// Needed to avoid use of Py_None, Py_True, and Py_False;
// which cause inability to use DELAYLOAD
HMODULE pythonDll = GetModuleHandle(L"python36.dll");
if (pythonDll == nullptr)
{
throw gcnew NotSupportedException(L"GS_ERR_CannotInitialize");
}
PythonHelper::_pyNone = (PyObject*)GetProcAddress(pythonDll, "_Py_NoneStruct");
PythonHelper::_pyTrue = (PyObject*)GetProcAddress(pythonDll, "_Py_TrueStruct");
PythonHelper::_pyFalse = (PyObject*)GetProcAddress(pythonDll, "_Py_FalseStruct");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
444 次 |
| 最近记录: |