Skip to content
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

Load dynamically libjulia.dll fails on Win32 from python and LoadLibrary? #57246

Open
Nelson-numerical-software opened this issue Feb 3, 2025 · 5 comments

Comments

@Nelson-numerical-software

Code below works on windows x86_64 but not on windows x86

Minimal code:

import os
import ctypes
julia_directory = 'D:/julia-1.11.3-win32/julia-1.11.3/bin'
os.chdir(julia_directory)
print("Current Directory:", os.getcwd())
julia_dll = 'libjulia.dll'
library_path = os.path.abspath(julia_dll)
julia_library = ctypes.CDLL(library_path)

result on windows x86:

D:\Developpements\Github\nelson-lang\nelson>python
Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import ctypes
>>> julia_directory = 'D:/julia-1.11.3-win32/julia-1.11.3/bin'
>>> os.chdir(julia_directory)
>>> print("Current Directory:", os.getcwd())
Current Directory: D:\julia-1.11.3-win32\julia-1.11.3\bin
>>> julia_dll = 'libjulia.dll'
>>> library_path = os.path.abspath(julia_dll)
>>> julia_library = ctypes.CDLL(library_path)
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
    julia_library = ctypes.CDLL(library_path)
  File "C:\WindowsTools\Python313\Lib\ctypes\__init__.py", line 390, in __init__
    self._handle = _dlopen(self._name, mode)
                   ~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 nest pas une application Win32 valide
>>

Julia version downloaded from https://julialang-s3.julialang.org/bin/winnt/x86/1.11/julia-1.11.3-win32.zip

from C++ code with MSVC 2022 win32 build as compiler LoadLibrary fails with error:

Unable to load dependent library D:\julia-1.11.3-win32\julia-1.11.3\bin\libjulia-codegen.dll

Same code with x64 build and julia x64 works perfectly.

Do not hesitate to close it if it is a duplicated bug

@vtjnash
Copy link
Member

vtjnash commented Feb 3, 2025

IIUC, we print the actual error message after the "Unable to load dependent library" text, though you could also try loading it (the libjulia-codegen.dll path) into python directly. My recollection of dealing with python.exe in the distant past is that they decided to statically link some stuff into it on Windows for better performance on x86, so the python executable can behave unreliably if you then try to dlopen things from it with ctypes.

@Nelson-numerical-software
Copy link
Author

Python's code is here only to have a basic reproductible code.
Main trouble is with LoadLibrary C/C++ code with same trouble.
LoadLibrary with libjulia.dll works on x64 windows but not on win32 build

@Nelson-numerical-software
Copy link
Author

libjulia-codegen.dll seems to have a unresolved dependency (I also tried with installer 1.11.3)

Win32
Image
dbghelp not found and seems to search x64 where it should be x86

To compare with x64 version:
Image

Please also notice is reproduced on 3 pcs and win32 github CI

@vtjnash
Copy link
Member

vtjnash commented Feb 3, 2025

I do not know why your system is missing dbghelp.dll, as that is part of your OS, and not a part of Julia

@Nelson-numerical-software
Copy link
Author

not also available on Github CI worker (standard github windows image)
Please notice that Julia.exe win32 starts but loadLibrary (or dependency walker) seems to find dbghelp.dll win32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants