zoukankan      html  css  js  c++  java
  • 【未完待补充】linux 设置So动态库链接路径

    缘起

    安装python的包Rtree(Rtree-0.8.2),但需要先安装C语言依赖包spatialindex-src(spatialindex-src-1.8.5)。在安装完spatialindex-src后,再安装Rtree过程中出现问题:

    dimite@ubuntu:~/wzh/Rtree-0.8.2$ python setup.py build
    Traceback (most recent call last):
      File "setup.py", line 4, in <module>
        import rtree
      File "/home/dimite/wzh/Rtree-0.8.2/rtree/__init__.py", line 1, in <module>
        from .index import Rtree
      File "/home/dimite/wzh/Rtree-0.8.2/rtree/index.py", line 6, in <module>
        from . import core
      File "/home/dimite/wzh/Rtree-0.8.2/rtree/core.py", line 106, in <module>
        rt = ctypes.CDLL(lib_name)
      File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: libspatialindex_c.so.4: cannot open shared object file: No such file or directory

    错误日志提示找不到动态链接库 libspatialindex_c.so.4,利用命令寻找动态链接库

    dimite@ubuntu:~/wzh/Rtree-0.8.2$ sudo find / -name libspatialindex_c.so.4
    [sudo] password for dimite: 
    /usr/local/lib/libspatialindex_c.so.4
    /home/dimite/wzh/spatialindex-src-1.8.5/.libs/libspatialindex_c.so.4

    需要四个动态链接库文件,都在/usr/local/lib中

    dimite@ubuntu:~/wzh/Rtree-0.8.2$ ls /usr/local/lib | grep libspatialindex | grep so
    libspatialindex_c.so
    libspatialindex_c.so.4
    libspatialindex_c.so.4.0.1
    libspatialindex.so
    libspatialindex.so.4
    libspatialindex.so.4.0.1

    解决

    方法一:
    把动态链接库所在的路径添加到/etc/ld.so.conf中

    include /etc/ld.so.conf.d/*.conf
    /usr/local/lib/

    然后更新/etc/so.cache

    sudo  ldconfig

    方法二:
    同方法一,把具体的so链接库写到/etc/ld.so.conf.d/下的conf文件中

    /usr/local/lib/

    方法三:
    设置$LD_LIBRARY_PATH=库所在目录(多个目录用:分隔)

    结论

    以root身份把库路径加入到/etc/ld.so.conf或在/etc/ld.so.conf.d中创建特定的.conf文件,运行ldconfig更新动态链接库

    设置$LD_LIBRARY_PATH=库所在目录(多个目录用:分隔)

    深究

    python怎么调用c的库

    python的setup.py 怎么执行,里边没有看到具体的build、install字眼

    ctype里的__init__.py又是怎么和动态链接库a联系在一起

  • 相关阅读:
    ps4 如何导出切片 单个图片
    测试webservice的时候,如果出现这个错误:"The test form is only available for requests from the local machine"
    js jquery 按钮点击后 60秒之后才能点击 60秒倒计时
    有空研究一下 superwebsocket (底层是 supersocket) 用来实现 web聊天什么的
    Vue学习笔记一:初识Vue
    被爬虫了,嘻嘻嘻
    Mybatis-generator自动生成器
    SpringCloud笔记五:Feign
    SpringCloud笔记四:Ribbon
    SpringCloud笔记三:Eureka服务注册与发现
  • 原文地址:https://www.cnblogs.com/kaituorensheng/p/4948046.html
Copyright © 2011-2022 走看看