Home > other >  libc dll file is missing on windows 10
libc dll file is missing on windows 10

Time:01-15

I'm trying to run this code in vscode for a school task, but I keep getting an error of a missing file 'libc.dll' I am somewhat confused of this file since I am new to this and not sure where to look for this file... Can someone explain to me what does this error actually mean and why I can't locate the file?

from ctypes import *

libc = CDLL("libc.dll")

libc.printf("hello everybody\n".encode('ascii'))

The error I'm getting:

Traceback (most recent call last): File "c:\Users\User\Desktop\2-3.py", line 3, in libc = CDLL("libc.dll")

File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\ctypes_init_.py", line 376, in init self._handle = _dlopen(self._name, mode)

FileNotFoundError: Could not find module 'libc.dll' (or one of its dependencies). Try using the full path with constructor syntax.

CodePudding user response:

[GNU]: The GNU C Library (glibc) (if this is what your libc.dll refers to) states (emphasis is mine):

The GNU C Library project provides the core libraries for the GNU system and GNU/Linux systems, as well as many other systems that use Linux as the kernel.

So, LibC is part of Nix world (which Win is not in).

MS's equivalent is CRT (also referred to as VCRT, MSVCRT, UCRT, ...: [MS.Learn]: Microsoft C runtime library (CRT) reference).
According to [Python.docs]: ctypes - Loading dynamic link libraries (make sure to also read the notes):

Here are some examples for Windows. Note that msvcrt is the MS standard C library containing most standard C functions, and uses the cdecl calling convention.

Example:

>>> import ctypes as cts
>>> import sys
>>>
>>> sys.version
'3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]'
>>>
>>>
>>> crt = cts.CDLL("msvcrt")
>>>
>>> crt.printf
<_FuncPtr object at 0x0000019AE5A48040>

You should also check:

Note: I also tried (a while ago) your code on Nix emulators (MSYS2, Cygwin) but they didn't work. The only thing that would work for sure is WSL2 ([MS.Learn]: Install Linux on Windows with WSL), as it has a genuine Linux kernel, but I'm not sure if that's relevant for you.

  • Related