I am on OSX trying to compile a common C library with setup.py distutils (for use in python using ctypes). I'm new to distutils, but I'm having problems when the shared library I want to compile (libreboundx.so) depends on another shared library (librebound.so). Explicitly, in the edit_orbits_direct.c file, I have
#include "rebound.h"
rebound.h is located in the / Users / dt / rebound / src / directory, and all functions in the rebound.h file are located in the librebound.so shared library, which is located in / Users / dt / rebound /.
Communication with cc will look.
cc -fPIC -shared reboundx.o -L/Users/dt/rebound -lrebound -o libreboundx.so
UPDATE . This situation looks exactly like the example at the end of the section. 3 at https://docs.python.org/2/extending/building.html . I updated my setup.py to simulate this:
libreboundxmodule = Extension('libreboundx', sources = [ 'src/reboundx.c', 'src/modify_orbits_direct.c'], include_dirs = ['src', '/Users/dt/rebound/src'], extra_compile_args=['-fstrict-aliasing', '-O3','-std=c99','-march=native', '-D_GNU_SOURCE', '-fPIC'], library_dirs=['/Users/dt/rebound'], libraries=['rebound'], )
This works great on startup.
pip install -e ./
Create output:
You are using pip version 7.0.3, however version 7.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Obtaining file:
but when i try
import reboundx
in Python, I get OSError: dlopen (libreboundx.so, 10): Symbol not found: _reb_boundary_particle_is_in_box, which is a function in another library (librebound.so) that is not even called in the code for libreboundx.so.
If I link the shared library to the cc command above, everything works, and I can use the libreboundx.so shared library perfectly in C. If I try to take the same libreboundx.so, I compile the cc command and paste it where setup will be installed .py and then try to import reboundx in python, instead I get
OSError: dlopen(/Users/dtamayo/Documents/workspace/reboundx/reboundx/../libreboundx.so, 10): Library not loaded: librebound.so
Link: /Users/dtamayo/Documents/workspace/reboundx/libreboundx.so Reason: image not found
Could this be a rpath problem where at runtime libreboundx.so doesn't know where to look for librebound.so?