0

I have a c++ dll project in Visual Studio 2022, that is meant to be called from python with ctypes. However, while the release DLL loads fine, the debug one cant be found.

Traceback (most recent call last):
  File "c:\...\RECURSIVE_NODES\python\gym_cartpole.py", line 25, in <module>
    libc = ctypes.cdll.LoadLibrary(dll_path)
  File "C:\miniconda3\lib\ctypes\__init__.py", line 451, in LoadLibrary
    return self._dlltype(name)
  File "C:\miniconda3\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'c:\...\RECURSIVE_NODES\x64\Debug\RECURSIVE_NODES.dll' (or one of its dependencies). Try using the full path with constructor syntax.

The DLL exists, and the path is correct, I have checked it 10 times over. It just wont work. Python code is as follows :

from pathlib import Path
dll_path = 'c:\...\RECURSIVE_NODES\x64\Debug\RECURSIVE_NODES.dll'
sPath = Path(dll_path)
print(sPath.is_file())  # returns true for both release and debug DLLs , so the file exists and is found by pathlib !!
libc = ctypes.cdll.LoadLibrary(dll_path)

The ellipsis in the path omit irrelevant parts of it. When I replace "Debug" with "Release" in the above path, the dll is correctly loaded. Whats the problem here ?

SOLUTION

As @MarkTolonen said in the comments, “Or one of its dependencies”. I checked those in the developper command prompt with dumpbin /dependents RECURSIVE_NODES.dll, and one of the differences between Release and Debug was the Adress Sanitizer's dll. For some reason Visual Studio was not able to find it, even though I was using its own debugger. Thats not the first time aSan has caused me troubles, so I disabled it, recompiled and python now finds the dll.

Yeb02
  • 21
  • 4
  • Does that happen on the computer you developed the *.dll* (with *VStudio* installed)? – CristiFati Mar 13 '23 at 14:38
  • “Or one of its dependencies” – Mark Tolonen Mar 13 '23 at 15:00
  • @CristiFati yes. RECURSIVE_NODES is the vs solution. – Yeb02 Mar 13 '23 at 15:02
  • *OK*, what if you launch *Python* from the *VStudio* console (if you don;t know how, check [\[SO\]: How to build a DLL version of libjpeg 9b? (@CristiFati's answer)](https://stackoverflow.com/a/44469099/4788546) *Prepare the ground* section)? For more debugging, check [\[SO\]: Discover missing module using command-line ("DLL load failed" error) (@CristiFati's answer)](https://stackoverflow.com/a/74883130/4788546) – CristiFati Mar 13 '23 at 15:06
  • @CristiFati that's what I am doing already, I tried both running from VS and from python dllUser.py in the command line. Sorry I should have mentioned it. I found the problem, editing my post to add the answer. – Yeb02 Mar 13 '23 at 15:22

0 Answers0