numpy.distutils, windows dll vs lib
Hi, recently, I got some problems detecting a dynamic library (dll) with numpy.distutils. Basically, I have a package which uses a class derived from system_info from numpy.distutils to detect a dll I use through ctypes. If only the dll is present, my numpy.distutils.system_info derived class does not find the library; if the .lib is present too, then it is detected. Why is that ? Can I modify my class do detecting the dll is enough ? I don't know how windows dynamic linking and dynamically loaded libraries work, and I am kind of confused by this (I thought .lib was .a, and .dll was .so, and that symbols were not exported by default on windows contrary to Unix, but the difference seems more subtle than this....). cheers, David
David Cournapeau wrote:
Hi,
recently, I got some problems detecting a dynamic library (dll) with numpy.distutils. Basically, I have a package which uses a class derived from system_info from numpy.distutils to detect a dll I use through ctypes. If only the dll is present, my numpy.distutils.system_info derived class does not find the library; if the .lib is present too, then it is detected. Why is that ? Can I modify my class do detecting the dll is enough ? I don't know how windows dynamic linking and dynamically loaded libraries work, and I am kind of confused by this (I thought .lib was .a, and .dll was .so, and that symbols were not exported by default on windows contrary to Unix, but the difference seems more subtle than this....).
Generally, you don't use .dll files to link against. With MSVC, you need a .lib file corresponding to your target .dll file which has the symbols. mingw and cygwin use similar .a files. This information is coded in the system_info.library_extensions() method, which you can override if you need something different. Of course, since you don't mention what methods on system_info that you are using, I can't quite be sure this will satisfy your needs. Note that so_ext here is obtained from the distutils configuration for your platform and is the file extension for extension modules, thus '.pyd' on Windows, not '.dll'. def library_extensions(self): static_exts = ['.a'] if sys.platform == 'win32': static_exts.append('.lib') # .lib is used by MSVC if self.search_static_first: exts = static_exts + [so_ext] else: exts = [so_ext] + static_exts if sys.platform == 'cygwin': exts.append('.dll.a') if sys.platform == 'darwin': exts.append('.dylib') return exts -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
David Cournapeau wrote:
Hi,
recently, I got some problems detecting a dynamic library (dll) with numpy.distutils. Basically, I have a package which uses a class derived from system_info from numpy.distutils to detect a dll I use through ctypes. If only the dll is present, my numpy.distutils.system_info derived class does not find the library; if the .lib is present too, then it is detected. Why is that ? Can I modify my class do detecting the dll is enough ? I don't know how windows dynamic linking and dynamically loaded libraries work, and I am kind of confused by this (I thought .lib was .a, and .dll was .so, and that symbols were not exported by default on windows contrary to Unix, but the difference seems more subtle than this....).
Generally, you don't use .dll files to link against. With MSVC, you need a .lib file corresponding to your target .dll file which has the symbols. mingw and cygwin use similar .a files. This information is coded in the system_info.library_extensions() method, which you can override if you need something different. Of course, since you don't mention what methods on system_info that you are using, I can't quite be sure this will satisfy your needs. Sorry for the lack of details; I did this a long time ago, and the
Robert Kern wrote: problem popped up for some people my package with windows (which I don't at all) just recently. I don't use the library for linking: I only need to be able to load it dynamically through ctypes. What I did is simply overriding the calc_info method, in which I try to detect both library and header files. For the library, I do the following: # Look for the shared library sndfile_libs = self.get_libs('sndfile_libs', self.libname) lib_dirs = self.get_lib_dirs() for i in lib_dirs: tmp = self.check_libs(i, sndfile_libs) if tmp is not None: info = tmp break else: return When I look at the system_info.check_libs code, it looks like it is trying to look for any extension, and the first found is returned... But this is not what I get, and I am not sure to see what I am doing wrong. cheers, David
David Cournapeau wrote:
I don't use the library for linking: I only need to be able to load it dynamically through ctypes. What I did is simply overriding the calc_info method, in which I try to detect both library and header files. For the library, I do the following:
# Look for the shared library sndfile_libs = self.get_libs('sndfile_libs', self.libname) lib_dirs = self.get_lib_dirs() for i in lib_dirs: tmp = self.check_libs(i, sndfile_libs) if tmp is not None: info = tmp break else: return
When I look at the system_info.check_libs code, it looks like it is trying to look for any extension, and the first found is returned... But this is not what I get, and I am not sure to see what I am doing wrong.
Well, since the first line of that method is this: exts = self.library_extensions() I conclude that if you were to override that method to return only ['.dll'], then your code will work. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Hello all ----- Original Message ----- From: "David Cournapeau" <david@ar.media.kyoto-u.ac.jp> To: "Discussion of Numerical Python" <numpy-discussion@scipy.org> Sent: Friday, March 16, 2007 6:51 AM Subject: Re: [Numpy-discussion] numpy.distutils, windows dll vs lib
Robert Kern wrote:
David Cournapeau wrote:
<snip>
Generally, you don't use .dll files to link against. With MSVC, you need a .lib file corresponding to your target .dll file which has the symbols. mingw and cygwin use similar .a files. This information is coded in the system_info.library_extensions() method, which you can override if you need something different. Of course, since you don't mention what methods on system_info that you are using, I can't quite be sure this will satisfy your needs. Sorry for the lack of details; I did this a long time ago, and the problem popped up for some people my package with windows (which I don't at all) just recently.
I don't use the library for linking: I only need to be able to load it dynamically through ctypes. What I did is simply overriding the calc_info method, in which I try to detect both library and header files. For the library, I do the following:
You might try numpy.ctypeslib.load_library. Cheers, Albert
Albert Strasheim wrote:
You might try numpy.ctypeslib.load_library.
I tried this some time ago, and I couldn't make it work as I wanted (cannot remember what exactly, this was like 6 months ago), and I found more reliable to detect the library when installing the package, and hardcoding the path at configuration time. And I need the header file anyway, now, so I need to do use numpy.distutils anyway. cheers, David P.S: Alber, I saw on your page that you had some problems with my package pyem. Could it be possible to have more details, so that I can try to solve them ?
participants (3)
-
Albert Strasheim
-
David Cournapeau
-
Robert Kern