ctypes problem loading libc.so on FreeBSD current
Marcus von Appen
mva at FreeBSD.org
Fri Feb 13 07:50:03 UTC 2015
On, Fri Feb 13, 2015, Craig Rodrigues wrote:
> Hi,
>
> I am looking at this blog post for loading libc with ctypes:
>
> http://blogs.freebsdish.org/rpaulo/2008/11/30/sysctlbyname3-and-others-from-python/
>
> I am using this version of python from ports:
>
>
> Name : python
> Version : 2.7_2,2
> Installed on : Mon Jan 12 22:10:27 PST 2015
> Origin : lang/python
> Architecture : freebsd:11:x86:64
> Prefix : /usr/local
> Categories : python lang ipv6
> Licenses :
> Maintainer : python at FreeBSD.org
> WWW : http://www.python.org/
> Comment : The "meta-port" for the default version of Python
> interpreter
> Annotations :
> repo_type : binary
> repository : FreeBSD
> Flat size : 38.0B
> Description :
> Python is an interpreted object-oriented programming language, and is
> often compared to Tcl, Perl or Scheme.
> This is a meta port to the Python interpreter and provides symbolic links
> to bin/python, bin/pydoc, bin/idle and so on to allow compatibility with
> version agnostic python scripts.
>
> WWW: http://www.python.org/
>
>
>
> I have this test program
>
> import ctypes
>
> mylib = ctypes.CDLL("libc.so")
> print(mylib)
>
> On FreeBSD 9, this program works, and I get a handle to libc.so.
>
> On FreeBSD-CURRENT, I get this:
>
> File "a.py", line 3, in <module>
> mylib = ctypes.CDLL("libc.so")
> File "/usr/local/lib/python2.7/ctypes/__init__.py", line 365, in __init__
> self._handle = _dlopen(self._name, mode)
> OSError: /usr/lib/libc.so: invalid file format
>
>
> The problem seems to be that on FreeBSD 9,
> /usr/lib/libc.so is a symlink to /lib/libc.so.7, while
> on FreeBSD-CURRENT, /usr/lib/libc.so contains this:
>
> /* $FreeBSD: head/lib/libc/libc.ldscript 258283 2013-11-17 22:52:17Z peter
> $ */
> GROUP ( /lib/libc.so.7 /usr/lib/libc_nonshared.a
> /usr/lib/libssp_nonshared.a )
>
>
> Any ideas what the problem is?
You described the problem above. ctypes is unable to load linker
scripts. The general advise is to use find_library():
>>> import ctypes
>>> import ctypes.util
>>> clib = ctypes.util.find_library("c")
>>> print clib
libc.so.7
>>> dll = ctypes.CDLL(clib)
Cheers
Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-python/attachments/20150213/8b20c3a6/attachment.sig>
More information about the freebsd-python
mailing list