1

I'm try to integrate with others who give to me a shared library just only .so files and the .h files.
In mac os, the shared library should be .dylib, But I don't how to set the environment or other way to solve the problems When I want to try to link with the shared library .so files in mac.

I have a pyd/pyx file I created manually. for example, just I have a named hellopy.so shared library. the Distutils setup.py files:

from setuptools import setup, find_packages
from Cython.Build import cythonize
from Cython.Distutils import build_ext, Extension

other_dir=''
cython_header_dir =''
common_args = {
"include_dirs": [other_dir],
"library_dirs": [other_dir],
"language": "c++",
"cython_include_dirs": [cython_header_dir],
}

extensions = [
Extension(name="api.api",
          sources=["api/api.pyx"],

          extra_compile_args=[],
          extra_link_args=[],
          # todo fix libraries problems
          libraries=["hellopy"],
          **common_args),

setup(

    include_package_data=True,
    install_requires=["Cython>=0.22"],
    setup_requires=["Cython>=0.22"],
    packages=find_packages(),
    cmdclass={"build_ext": build_ext},
    ext_modules=cythonize(extensions),
    exclude_package_data={"": ["*.cpp"]}
)

then try to compile the package.

python setup.py build_ext --inplace
ld: library not found for -lhellopy
clang: error: linker command failed with exit code 1 (use -v to see invocation)
nooper
  • 691
  • 1
  • 9
  • 25
  • See here for a list of additional options for setting additional directories to your library path in your `setup.py`. https://docs.python.org/2/distutils/apiref.html#distutils.core.Extension – cel May 31 '15 at 05:58
  • @cel I have consider of this solution ,but The shared libraries is not the standard library.So I can't compile the sources code or somethings. – nooper May 31 '15 at 06:04
  • I didn't get that. Can you show us the most relevant parts of your `pyx` and `pyd` files as well? If done correctly you only have to make your compiler aware of where it can find the library. – cel May 31 '15 at 06:12
  • Do you actually want to use Cython, or are you just using it to access the shared library? If you don't need Cython, a simpler way to access shared libraries from Python is to use [ctypes](https://docs.python.org/3/library/ctypes.html) – PM 2Ring May 31 '15 at 07:55
  • The exactly thing it's how could I to set the path or something to find the library. @cel I have consider of this solution, http://stackoverflow.com/questions/16993927/using-cython-to-link-python-to-a-shared-library?rq=1 But In Mac OS, there is no `LD_LIBRARY_PATH` configuration in os environment. – nooper May 31 '15 at 15:42

0 Answers0