Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Steve Ellcey  <sellcey@mips.com>
Cc: gdb@sourceware.org
Subject: Re: GDB/Python configuration question
Date: Fri, 08 Nov 2013 02:45:00 -0000	[thread overview]
Message-ID: <20131108024528.GN7563@adacore.com> (raw)
In-Reply-To: <d0bdf801-dcec-4757-81d9-f1cb92326ab9@BAMAIL02.ba.imgtec.org>

[-- Attachment #1: Type: text/plain, Size: 860 bytes --]

> The reason is that "python-config.py --ldflags" is returning:
> 
> 	-L/local/home/sellcey/gcc/mt/src/install-python/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
> 
> and if I link with this I get undefined references because libpython2.7 is
> listed *after* libutil, libm, and libdl and is an archive library.  If I
> move it before (by hand) the link works.
> 
> Has anyone else run into this?

I don't remember which issues we ran into when building GDB against
a static version of libpython, but we've had to make a number of
changes to python-config.py. I do see in your output the one I remember
making for GNU/Linux, though (-export-dynamic).

The only difference in outupt with the script we use is an extra
-static-libgcc at the end.

JIC, here is our python-config.py, in case it helps in your case.

-- 
Joel

[-- Attachment #2: python-config.py --]
[-- Type: text/x-python, Size: 5214 bytes --]

# Program to fetch python compilation parameters.
# Copied from python-config of the 2.7 release.

import sys
import os
import getopt
from distutils import sysconfig
import platform

valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
              'ldflags', 'help']

def exit_with_usage(code=1):
    sys.stderr.write ("Usage: %s [%s]\n" % (sys.argv[0],
                                          '|'.join('--'+opt for opt in valid_opts)))
    sys.exit(code)

try:
    opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
except getopt.error:
    exit_with_usage()

if not opts:
    exit_with_usage()

pyver = sysconfig.get_config_var('VERSION')
getvar = sysconfig.get_config_var
abiflags = getattr (sys, "abiflags", "")

opt_flags = [flag for (flag, val) in opts]

if '--help' in opt_flags:
    exit_with_usage(code=0)

def to_unix_path(path):
    """On Windows, returns the given path with all backslashes
    converted into forward slashes.  This is to help prevent problems
    when using the paths returned by this script with cygwin tools.
    In particular, cygwin bash treats backslashes as a special character.

    On Unix systems, returns the path unchanged.
    """
    if os.name == 'nt':
        path = path.replace('\\', '/')
        # At AdaCore, the prefix we provide to the configure script
        # does not contain drive letters.  If this path starts with
        # a drive letter, then we need to remove it.  Otherwise,
        # the crude path-matching algorithm used in the configure
        # script to determine whether the path ought to be relocatable
        # or not will trip, purely because it does not know about
        # drive letters.
        import re
        if re.match("[a-zA-Z]:/", path):
            path = path[2:]
    return path

for opt in opt_flags:
    if opt == '--prefix':
        print (to_unix_path(sysconfig.PREFIX))

    elif opt == '--exec-prefix':
        print (to_unix_path(sysconfig.EXEC_PREFIX))

    elif opt in ('--includes', '--cflags'):
        flags = ['-I' + sysconfig.get_python_inc(),
                 '-I' + sysconfig.get_python_inc(plat_specific=True)]
        if opt == '--cflags':
            flags.extend(getvar('CFLAGS').split())
        print (to_unix_path(' '.join(flags)))

    elif opt in ('--libs', '--ldflags'):
        libs = []
        if getvar('LIBS') is not None:
            libs.extend(getvar('LIBS').split())
        if getvar('SYSLIBS') is not None:
            libs.extend(getvar('SYSLIBS').split())
        libs.append('-lpython'+pyver + abiflags)
        # add the prefix/lib/pythonX.Y/config dir, but only if there is no
        # shared library in prefix/lib/.
        if opt == '--ldflags':
            if not getvar('Py_ENABLE_SHARED'):
                # Do not rely on the LIBPL variable as the offical version
                # of this script does, as this variable is not relocated
                # (which means that if Python is installed at at different
                # location than the configure prefix, LIBPL is wrong).
                #
                # FIXME: The following code assumes that Python was
                # configured without --with-libdir, and thus is not
                # strictly correct either.
                if os.name == 'nt':
                    from platform import architecture
                    if architecture()[0].startswith('64'):
                        # For 64bit Windows <prefix>/libpython[...].dll
                        # is actually an import library.
                        libdir = sysconfig.PREFIX
                    else:
                        # On 32bit Windows, however, the import library
                        # is inside <prefix>/libs.
                        libdir = sysconfig.PREFIX + '/libs'
                else:
                    libdir = sysconfig.get_python_lib(standard_lib=True) \
                               + '/config'
                libs.insert(0, '-L' + libdir)
                if platform.system() == 'Linux':
                    # Make sure that the loader can resolve symbols from
                    # the libpython archive when loading modules implemented
                    # as DSOs (Eg: "import time").  This is to work around
                    # a side-effect of linking against the static version
                    # of libpython.
                    libs.insert(0, '-Xlinker -export-dynamic')
            linkforshared = getvar('LINKFORSHARED')
            if linkforshared is not None:
                if platform.system() == 'AIX':
                    # On this platform, one of the options is
                    # missing the full path to the .exp file
                    # (an Export file), causing the link to fail.
                    # Fix that path...
                    linkforshared = linkforshared.replace(
                        '-bE:Modules/python.exp',
                        '-bE:%s/python.exp' % libdir)
                    # The python library also depends on libm, which
                    # needs to be added after -lpython...
                    linkforshared += ' -lm'
                libs.extend(linkforshared.split())
        print (to_unix_path(' '.join(libs)))


      reply	other threads:[~2013-11-08  2:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08  0:03 Steve Ellcey 
2013-11-08  2:45 ` Joel Brobecker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131108024528.GN7563@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb@sourceware.org \
    --cc=sellcey@mips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox