* GDB/Python configuration question
@ 2013-11-08 0:03 Steve Ellcey
2013-11-08 2:45 ` Joel Brobecker
0 siblings, 1 reply; 2+ messages in thread
From: Steve Ellcey @ 2013-11-08 0:03 UTC (permalink / raw)
To: gdb
This question should probably be asked on the python list but since the only
reason I am building python is to build gdb I thought I would start here and
find out if I am really the only person running into this issue and in the
hopes that someone here has some good connections into that project and could
forward the bug on.
I am building and installing python into a non-standard location on my
x86 linux box (ubuntu 12.04), this seems to all work fine. It builds and
installs an archive, but not shared, python library (libpython2.7.a). I add
the bin directory containing python-config.py to my PATH and then I try to
configure and build gdb (configuring with --with-python).
The GDB configure script uses python-config.py to set python_libs and
compiles and links a test program that calls Py_Initialize to see if
the python installation is good. This test fails for me.
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?
Steve Ellcey
sellcey@mips.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: GDB/Python configuration question
2013-11-08 0:03 GDB/Python configuration question Steve Ellcey
@ 2013-11-08 2:45 ` Joel Brobecker
0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2013-11-08 2:45 UTC (permalink / raw)
To: Steve Ellcey; +Cc: gdb
[-- 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)))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-08 2:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-08 0:03 GDB/Python configuration question Steve Ellcey
2013-11-08 2:45 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox