New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctypes.util.find_msvcrt() function #46126
Comments
I'm uploading this patch for discussion, in case someone cares. This code (for Windows) adds a function ctypes.util.find_msvcrt(). This Further, this patch changes ctypes.util.find_library(name) so that the |
In general I like the idea. But wouldn't it be better to have a cross |
The cross-platform function is ctypes.util.find_library, which is This patch changes it so that, on Windows, find_library("c") or The runtime lib in Windows is special anyway; the 'open' function, for However, the easiest way on Linux (don't know about other platforms) to |
I found the code I wrote some time ago for the same purpose: import sys
if sys.platform == 'win32':
# Parses sys.version and deduces the version of the compiler
import distutils.msvccompiler
version = distutils.msvccompiler.get_build_version()
if version is None:
# This logic works with official builds of Python.
if sys.version_info < (2, 4):
clibname = 'msvcrt'
else:
clibname = 'msvcr71'
else:
if version <= 6:
clibname = 'msvcrt'
else:
clibname = 'msvcr%d' % (version * 10)
# If python was built with in debug mode
import imp
if imp.get_suffixes()[0][0] == '_d.pyd':
clibname += 'd'
standard_c_lib = ctypes.cdll.LoadLibrary(clibname+'.dll') This code works on all pythons I have on my machine: official builds, But to me this seems more robust than a text search in the executable. |
Amaury Forgeot d'Arc schrieb:
What I do not like about your code is that it imports distutils. What do you think? |
Fine with me. |
Committed in trunk as rev. 63395. I've changed the code that Amaury |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: