Delay loading python dll when embedding python + numpy

I am creating a C ++ application that will call python + numpy, and I would like a DELAYLOAD python dll. I am using Visual Studio 2015 for Windows with 64-bit python 3.6. DELAYLOAD works fine until I use numpy. Once I call import_array() , I can no longer build using the DELAYLOAD option. Linker Error

LNK1194 cannot delay "python36.dll" due to import of data symbol "__imp_PyExc_ImportError"; link without /DELAYLOAD:python36.dll.

Here is my code:

 // Initialize python Py_Initialize(); // If I remove this line, I am able to build with DELAYLOAD import_array(); 

Is there a way to make a possible delay when using numpy?

Alternative question: is it possible to create and populate numpy.recarray data without calling import_array ()?

EDIT: I decided to get rid of import_array (). Here are some of the code I use to initialize 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"); } 
+7
c ++ c python numpy visual-c ++
source share
2 answers

Is there a way to make a possible delay when using numpy?

You may not be able to use DELAYLOAD with import_array :

  • You cannot delay loading a DLL if data is imported from it ( official documentation ).

  • import_array imports the module in which the table of function pointers is stored, and the correct variable points to it ( official documentation ).

I doubt that you are dealing with a case of exporting classes and exporting data. See this , this or this .

+1
source share

It can also be triggered by optimizations, as shown here .

You can also try Remove unreferenced code and data in the project settings.

0
source share

All Articles