[Numpy-discussion] when will osx linker option -bundle be reflected in distutils

Robert Kern robert.kern at gmail.com
Mon Jan 5 20:30:12 EST 2009


On Mon, Jan 5, 2009 at 18:48, Garry Willgoose
<garry.willgoose at newcastle.edu.au> wrote:
>> > I was just wondering what plans there were to reflect the different
>> > linker options (i.e. -bundle instead of -shared) that are required
>> on
>> > OSX in the fcompiler files within distutils. While its a minor thing
>> > it always catches the users of my software when they either install
>> > fresh or update numpy ... and sometimes on a bad day it even catches
>> > me ;-)
>>
>> I'm sorry; I don't follow. What problems are you having? --
>> -- Robert Kern
>>
> -----------------------------------------------
>
> OK for example the distribution g95.py in distutils/fcompiler has the
> following code
>
>        executables = {
>            'version_cmd'  : ["g95", "--version"],
>            'compiler_f77' : ["g95", "-ffixed-form"],
>            'compiler_fix' : ["g95", "-ffixed-form"],
>            'compiler_f90' : ["g95"],
>            'linker_so'    : ["g95","-shared"],
>            'archiver'     : ["ar", "-cr"],
>            'ranlib'       : ["ranlib"]
>            }
>
> For osx you need to modify it to
>
>      executables = {
>            'version_cmd'  : ["g95", "--version"],
>            'compiler_f77' : ["g95", "-ffixed-form"],
>            'compiler_fix' : ["g95", "-ffixed-form"],
>            'compiler_f90' : ["g95"],
>            'linker_so'    : ["g95","-shared"],
>            'archiver'     : ["ar", "-cr"],
>            'ranlib'       : ["ranlib"]
>            }
>    import sys
>    if sys.platform.lower() == 'darwin':
>        executables[linker_so'] = ["g95","-Wall -bundle"]
>
> The 'shared' option is not implemented in the osx linker. Not sure
> what the underlying difference between 'shared' and 'bundle' is but
> this substitution is necessary and this has been working for me for
> the last year or so. You also need the -Wall but for reasons that
> completely escape me.

-Wall absolutely should not affect anything except adding warning
messages. I suspect something else is getting modified when you do
that.

> The same goes for gfortran and intel (both of which I use) and I
> assume the other compilers that are available for OSX.

I've been building scipy for years with gfortran and an unmodified
numpy on OS X. The correct switches are added in the
get_flags_linker_so() method:

    def get_flags_linker_so(self):
        opt = self.linker_so[1:]
        if sys.platform=='darwin':
            # MACOSX_DEPLOYMENT_TARGET must be at least 10.3. This is
            # a reasonable default value even when building on 10.4 when using
            # the official Python distribution and those derived from it (when
            # not broken).
            target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)
            if target is None or target == '':
                target = '10.3'
            major, minor = target.split('.')
            if int(minor) < 3:
                minor = '3'
                warnings.warn('Environment variable '
                    'MACOSX_DEPLOYMENT_TARGET reset to %s.%s' % (major, minor))
            os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,
                minor)

            opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])
        else:
            opt.append("-shared")
        if sys.platform.startswith('sunos'):
            # SunOS often has dynamically loaded symbols defined in the
            # static library libg2c.a  The linker doesn't like this.  To
            # ignore the problem, use the -mimpure-text flag.  It isn't
            # the safest thing, but seems to work. 'man gcc' says:
            # ".. Instead of using -mimpure-text, you should compile all
            #  source code with -fpic or -fPIC."
            opt.append('-mimpure-text')
        return opt

If this is not working for you, please show me the error messages you get.

-- 
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



More information about the NumPy-Discussion mailing list