2

Checking dependencies with ldd on the *.so file produced by Cython, the dependencies contains myLib.o instead of libforcython.o

I do not grasp why it is trying to reach a myLib.o instead of libforcython as indicated in my setup.py .

During python execution of the module that produces an error similar to Cython unable to find shared object file . However contrary to the included links and answer, my problem does not seem to happen during the python initialization, but rather during the cythonization itself.


using these files:

example.pyx :

cdef extern from "myLib.h":
    void testFunction ()

setup.py:

from distutils.core import setup 
from distutils.extension import Extension
from Cython.Build import cythonize


pythoncallsc_extension = Extension (
    name = "pythoncallsc",
    sources=["./example.pyx"],
    libraries=["forcython"])

setup ( name = "pythoncallsc",
        ext_modules = cythonize ([pythoncallsc_extension]))

When I look at the log generated by python3 setup.py build_ext --inplace I can then clearly see in the commandline launching gcc, and it contains:

... -lforcython -lpython3.7m ...

So clearly gcc is linking against my library libforcython. The lib contains:

  • header myLib.h
  • generated libforcython.so file for the function void testFunction(void).

This lib is built separately and elsewhere in my system. I have checked the include and lib and they are clearly in the $PATH of my cython project.


The cythonization produces the library pythoncallsc.cpython-37m-x86_64-linux-gnu.so

But against all my expectations when I do:

ldd pythoncallsc.cpython-37m-x86_64-linux-gnu.so

linux-vdso.so.1 (0x00007ffee40fb000)
myLib.o => not found                     <=== HERE ???
libpython3.7m.so.1.0 => /path/to/lib...
libpthread.so.0 => ...
libc.so.6 => ...
...

Why is cython producing an output that depends on a myLib.o file and not on libforcython.so ?

This myLib.o file does not exists, and consequently that produces an error when I launch my module:

`ImportError: myLib.o: cannot open shared object file: No such file or directory`

Any clue ?

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169

1 Answers1

0

In case we have this error, we should check how the c library is built.

As suggested in the comments, the libforcython library was not built properly.

It was wrongly built using soname with gcc in the Makefile.

Correct:

gcc myLib.o -shared -fPIC -Wl,-soname,libforcython.so -o libforcython.so -lc

Incorrect:

gcc -shared -fPIC -Wl,-soname,myLib.o -o libforcython.so myLib.o -lc

In this case soname is not really useful because I don't use a version number for the library: a simpler use case.

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169