This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GDB/Python configuration question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]