0

I'm following the guide found here:

http://www.dalkescientific.com/writings/NBN/c_extensions.html

for creating C extensions to python. But when I try to run any python program after building that module, such as the first one listed or mandelbrot.py (listed towards the end of the page). I get the error on the line libc = ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL)

The error is:

Traceback (most recent call last):
File "cos.py", line 5, in < module >
libc = ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libc.dylib: cannot open shared object file: No such file or directory

I'm using Linux so I'm not sure if that is the problem. And if it is, how would I accomplish this on Linux? I know dll is how Windows refers to shared objects. But does the syntax change? I can't seem to find an answer anywhere.

2
  • When showing tracebacks like this put them in a codeblock to avoid this issue. Commented Oct 31, 2014 at 19:42
  • I should've do it considering it's pretty obvious to put tracebacks in a code block. I must've been in a rush at work and forgotten. My apologies. Commented Jan 8, 2015 at 5:51

1 Answer 1

1

On GNU/Linux the cos() function is located in a library called libm.so. So you need to replace "libc.dylib" with "libm.so".

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I'm an idiot, where do I replace that file exactly? Where is libc.dylib typically located? And what's the most reliable way to get a clean copy of libm.so?
No, you shouldn't replace any files on your system. Just change the code to ctypes.CDLL("libm.so", ctypes.RTLD_GLOBAL) instead of ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.