Skip to content

CDLL failed to load a dll file with a correct path. #137401

@codingshen

Description

@codingshen

Bug report

Bug description:

I have a Python project like this:
Project
|---libs
|------dylib.dll
main.py

then, I try to use ctypes to load that:

from ctypes import *
lib = CDLL("libs/dylib.dll")

CRASHED!

Traceback (most recent call last):
  File "...", line 4, in <module>
    spdlog_api = ctypes.CDLL("libs/dylib.dll")
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\ctypes\__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'lib/dylib.dll' (or one of its dependencies). Try using the full path with constructor syntax.

all right, lets use os to generate the full path.

os.path.dirname(os.path.abspath(__file__))+"/libs/spdlog-build.dll")

this works on my PC but CRASHED AGAIN ON ANOTHER COMPUTER!
It shows that ctypes can not load full path as well!

right , lets fix it!
then, I found that
NO! Ctypes is written in C so that I can only find the definition in ctypes.pyi

CPython versions tested on:

3.12

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtopic-ctypes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions