сtypes не видит DLL файл
У меня есть dll файл (lib1.dll
), скомпилирован на gcc mingw 12.2.0. С помощью ctypes
я подключаю эту библиотеку в код
Python:
from ctypes import *
lib = cdll.LoadLibrary("C:\\st2\\lib1.dll")
lib.print("Hello")
lib1.cpp
(код dll):
#include <iostream>
using namespace std;
void print(string st){
cout<<st;
}
И при попытке выполнить код выдается такая ошибка:
Traceback (most recent call last):
File "C:\st2\main.py", line 3, in <module>
lib=cdll.LoadLibrary("C:\\st2\\lib1.dll")
File "C:\Users\Professional\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "C:\Users\Professional\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\st2\lib1.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Все файлы в одной папке. Как решить данную проблему?
Источник: Stack Overflow на русском