Checking for libc vs. glibc using Python

Charles G Waldman cgw at fnal.gov
Thu Oct 21 05:37:47 EDT 1999


M.-A. Lemburg writes:
 > 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()

I would use "ldd" instead of "nm".  It's another hack, not much more
elegant, but a little more portable.  In particular it doesn't require 
that python was compiled -g.

I'm not sure how much the ldd output varies on different unices
(haven't tried this on BSD), but I think it should be pretty easy to
find a portable way search for the libc.so.* line in the output and
figure out the libc version.

This will fail if libc is linked statically, as far as I know this is
rarely done.  It's still less of a restriction than requiring python
to be built with debugging info.

It's still not exactly elegant but possibly a little more portable than 
what you were doing.






More information about the Python-list mailing list