Checking for libc vs. glibc using Python

M.-A. Lemburg mal at lemburg.com
Thu Oct 21 04:41:10 EDT 1999


Is it possible to examine a Python interpreter and check whether
it was compiled against libc5 or glibc2 (libc6) on Linux/*BSD/etc. ?

I'm currently using this hack, but would appreciate a more
elegant and portable solution:

def system_nm(progfile):

    try:
	f = os.popen('nm %s' % progfile)
    except os.error:
	return ''
    return f.read()

# Check for libc vs. glibc
nm_python = system_nm(sys.executable)
if string.find(nm_python,'libc_init') >= 0:
    libversion = 'libc'
elif string.find(nm_python,'GLIBC_') >= 0:
    pos = 0
    libversion = 'glibc'
    while 1:
	pos = string.find(nm_python,'GLIBC_',pos+1)
	if pos < 0:
	   break
	vstring = 'glibc' + nm_python[pos+6:pos+10]
	if vstring > libversion:
	    libversion = vstring
else:
    libversion = ''

Note that the above only works if the interpreter was compiled
with debugging information (e.g. with -g on Linux).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    71 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list