[Numpy-discussion] numpy.distutils, system_info and dll/exp/lib

David Cournapeau david at ar.media.kyoto-u.ac.jp
Thu May 31 23:14:51 EDT 2007


Hi,

    In one of my package, I use numpy.distutils.system_info to detect a 
C library. This works well on linux and Mac OS X, but on windows, the 
library is not detected if only the dll is present. If the .lib is 
there, then it is detected; the dll itself works OK (I can use it from 
ctypes normally). Am I doing something wrong in my configuration ?

"""
class SndfileNotFoundError(NotFoundError):
    """ sndfile (http://www.mega-nerd.com/libsndfile/) library not found.
    Directories to search for the libraries can be specified in the
    site.cfg file (section [sndfile])."""

class sndfile_info(system_info):
    #variables to override
    section         = 'sndfile'
    notfounderror   = SndfileNotFoundError
    libname         = 'sndfile'
    header          = 'sndfile.h'

    def __init__(self):
        system_info.__init__(self)

    def calc_info(self):
        """ Compute the informations of the library """
        prefix  = 'lib'

        # 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:
        #    raise self.notfounderror()
                   
        # Look for the header file
        include_dirs    = self.get_include_dirs()
        inc_dir         = None
        for d in include_dirs:
            p = self.combine_paths(d,self.header)
            if p:
                inc_dir     = os.path.dirname(p[0])
                headername  = os.path.abspath(p[0])
                break
        if inc_dir is not None and tmp is not None:
            if sys.platform == 'win32':
                # win32 case
                fullname    = prefix + tmp['libraries'][0] + \
                        '.dll'
            elif sys.platform == 'darwin':
                # Mac Os X case
                fullname    = prefix + tmp['libraries'][0] + '.' + \
                        str(SNDFILE_MAJ_VERSION) + '.dylib'
            else:
                # All others (Linux for sure; what about solaris) ?
                fullname    = prefix + tmp['libraries'][0] + '.so' + \
                        '.' + str(SNDFILE_MAJ_VERSION)
            fullname    = os.path.join(info['library_dirs'][0], fullname)
            dict_append(info, include_dirs=[inc_dir],
                    fullheadloc = headername,
                    fulllibloc  = fullname)
        else:
            return

        #print self
        self.set_info(**info)
        return
"""

    The problem is, the library I am using is distributed only as a dll, 
not with the .lib. Right now, users of my package need to generate the 
.lib by themselves from the dll, using visual studio compiler, which is 
really too much (specially since the library itself is fine; using the 
compiler is necessary only for distutils to find the library !).

    cheers,

    David



More information about the NumPy-Discussion mailing list