This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ctypes.util.find_library does not work under Solaris
Type: behavior Stage: resolved
Components: ctypes Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: FalkNisius, aliles, automatthias, kewang, laca, python-dev, skip.montanaro, theller, trent
Priority: normal Keywords: patch

Created on 2009-02-17 08:17 by kewang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
util.diff kewang, 2009-02-18 08:34
util.diff kewang, 2009-02-19 02:48 Fixed the TabError
Messages (7)
msg82303 - (view) Author: Ke Wang (kewang) Date: 2009-02-17 08:17
Under Solaris, find_library can not give the correct path.
Solaris does not have /sbin/ldconfig, so _findLib_gcc is used.

def _findLib_gcc(name):
        expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
        fdout, ccout = tempfile.mkstemp()
        cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; else CC=cc; fi;' \
              '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
            f = os.popen(cmd)
            trace =
            except OSError, e:
                if e.errno != errno.ENOENT:
        res =, trace)
        if not res:
            return None

I executed these code manually, and after ‘trace =‘, I printed
the content of 'trace', which was just as following:

Undefined			first referenced
 symbol  			    in file
main                                /usr/lib/crt1.o
ld: fatal: symbol referencing errors. No output written to /tmp/tmpYN85Fm
collect2: ld returned 1 exit status
msg82317 - (view) Author: Ke Wang (kewang) Date: 2009-02-17 10:54
I tested the command 'gcc -Wl,-t' on Ubuntu, it works fine.
But on Solaris, it doesn't work as expected.

Finally I find that gcc does not use GNU ld on Solaris, instead, it uses
SUN ld.
msg82412 - (view) Author: Ke Wang (kewang) Date: 2009-02-18 08:34
On Solaris, we can use crle to find system library path.

Attached a patch to get find_library work with Solaris.
msg82449 - (view) Author: Ke Wang (kewang) Date: 2009-02-19 02:48
Above patch failed in a TabError.
Attached a new one.
msg146076 - (view) Author: Falk Nisius (FalkNisius) Date: 2011-10-21 10:02
Under Ubuntu 11.04 is the _findLib_gcc used and not a ldconfig method.

Why should I install a gcc only to find a dynamic library ? It seems not a well design. The usage of ldconfig, what is more natural at a server in the net than a c compiler. Perhaps it can be changed in the next version, because I can see that on other os th ldconfig method would be preferred.

I'm not an python programmer and have not the possibilities to make a regeression test, thats why I can not help.
msg180725 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2013-01-27 00:23
Is there still time to get this bug fixed in 2.7.3? I patched my 2.7 ctypes/ with the latest version (offset a few lines, but no other problems) and verified that it seems to fix the issue.  When running as a main program I see this before running patch:

% python /opt/TWWfsw/python27/lib/python2.7/ctypes/
<CDLL '', handle fed807b8 at 82c320c>
<CDLL '', handle feb703a8 at 82c320c>

After applying the patch:
% python /opt/TWWfsw/python27/lib/python2.7/ctypes/
<CDLL '', handle fed807b8 at 82c296c>
<CDLL '', handle feb703a8 at 82c296c>
msg181305 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-04 00:27
New changeset d76fb24d79c3 by Benjamin Peterson in branch '2.7':
fix find_library on Solaris (closes #5289)

New changeset 73574de2068b by Benjamin Peterson in branch '3.3':
fix find_library on Solaris (closes #5289)

New changeset 640a80adb9df by Benjamin Peterson in branch 'default':
merge 3.3 (#5289)
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49539
2013-02-04 00:27:26python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg181305

resolution: fixed
stage: resolved
2013-01-28 11:50:36trentsetnosy: + trent
2013-01-27 00:23:38skip.montanarosetnosy: + skip.montanaro
messages: + msg180725
2012-12-13 11:26:37alilessetnosy: + aliles
2011-10-21 10:02:36FalkNisiussetnosy: + FalkNisius
messages: + msg146076
2011-10-17 08:25:35automatthiassetnosy: + automatthias
2010-08-05 00:46:44terry.reedysetversions: + Python 2.7, - Python 2.6
2009-02-19 02:48:55kewangsetfiles: + util.diff
messages: + msg82449
2009-02-18 21:19:46lacasetnosy: + laca
2009-02-18 08:34:11kewangsetfiles: + util.diff
keywords: + patch
messages: + msg82412
2009-02-17 10:54:30kewangsetmessages: + msg82317
2009-02-17 08:17:14kewangcreate