I am attempting to load two C++ DLLs in a Python program using ctypes, however, one of the modules throws an error despite the other loading completely fine. Here is the code:
import ctypes
os.add_dll_directory(r"C:\Users\{user}\PycharmProjects\pythonProject")
A = ctypes.cdll.LoadLibrary("A.dll")
B = ctypes.cdll.LoadLibrary("B.dll")
As stated, I am trying to load two DLLs, let's say we have "A.dll" and "B.dll".
"B.dll" is dependent on "A.dll", so I am loading "A.dll" first. This load works, so we know the libraries are located in the correct directory. However, when attempting to load "B.dll", this error is thrown:
FileNotFoundError: Could not find module 'B.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Since we know they are located in the correct directory, the issue could only be that it could not locate one of its dependencies. However, I already loaded the library that "B.dll" is dependent on, so I'm not sure what exactly could be missing.
When using this library elsewhere, such as in native C++ code, it is a requirement to also include the library's header file, for example "B.h". I'm wondering if that could be the issue here - is it necessary to somehow include the header file that is associated with "B.dll" in order to be located by ctypes?