Windows平台PySide6环境下加载MSVC2019编译的C++ DLL失败的问题求助
Windows平台PySide6环境下加载MSVC2019编译的C++ DLL失败的问题求助
大家好,我目前遇到了一个加载C++ DLL的棘手问题,先跟大家说明下我的开发环境:
Qt: 6.5.5, pyside 6, OS: windows, compiler for c++ libraries mscv2019
我的项目架构是核心逻辑用C/C实现,UI层基于QML开发。现在我想搭建一个子项目,用Python来处理业务逻辑,UI依旧保留QML,需要把C编译生成的DLL加载到Python代码中,让Python作为QML和C++核心逻辑之间的通信桥梁。
我已经尝试了两种加载DLL的方法,但都以失败告终:
方法1
dll_path = Path(r"C:\Simulator\Platform_Code\Build\QtCreator\outfiles\win64-x86-msvc\release\Test.dll") if not dll_path.exists(): print(f"DLL not found: {dll_path}") sys.exit(-1) cpp_lib = QLibrary(str(dll_path)) print(f"Attempting to load cpp_lib from: {cpp_lib}") result = cpp_lib.load() if not result: print("Hi " + cpp_lib.errorString()) sys.exit(-1) if not cpp_lib.load(): print(f"Failed to load the DLL: {cpp_lib.errorString()}") sys.exit(-1) print("DLL loaded successfully.")
方法2
def load_all_dlls(folder_path): for filename in os.listdir(folder_path): if filename.endswith('.dll'): full_path = os.path.join(folder_path, filename) try: ctypes.CDLL(full_path) print(f"Successfully loaded {full_path}") except Exception as e: print(f"Failed to load {full_path}: {e}") dll_path = Path(r"C:\Simulator\Platform_Code\Build\QtCreator\outfiles\win64-x86-msvc\release\Test.dll") if not dll_path.exists(): print(f"DLL not found: {dll_path}") sys.exit(-1) cpp_lib = QLibrary(str(dll_path)) print(f"Attempting to load cpp_lib from: {cpp_lib}")
不管用哪种方法,我都会收到如下错误提示:
Attempting to load cpp_lib from: <PySide6.QtCore.QLibrary(0x140b6b0eb50) at 0x00000140B8C6F240> Hi Cannot load library C:\\Simulator\\Platform_Code\\Build\\QtCreator\\outfiles\\win64-x86-msvc\\release\\Test.dll: The specified module could not be found.
有没有大佬能帮我分析下问题出在哪?应该怎么解决这个DLL加载失败的问题呢?
备注:内容来源于stack exchange,提问作者Shubhangani
相关产品推荐
相关产品推荐

