- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 Python 中,ctypes.util.find_library
可用于以类似于编译器的方式定位库。在 Mac OSX 中,该函数返回完整路径名。但是在 linux 中,只返回文件名。 (这里是 docs )
有没有办法在 linux 中也获得完整路径?
最佳答案
您可以加载库并使用 dl_iterate_phdr
迭代加载的库:
#!python
from ctypes import *
from ctypes.util import find_library
# this struct will be passed as a ponter,
# so we don't have to worry about the right layout
class dl_phdr_info(Structure):
_fields_ = [
('padding0', c_void_p), # ignore it
('dlpi_name', c_char_p),
# ignore the reset
]
# call back function, I changed c_void_p to c_char_p
callback_t = CFUNCTYPE(c_int,
POINTER(dl_phdr_info),
POINTER(c_size_t), c_char_p)
dl_iterate_phdr = CDLL('libc.so.6').dl_iterate_phdr
# I changed c_void_p to c_char_p
dl_iterate_phdr.argtypes = [callback_t, c_char_p]
dl_iterate_phdr.restype = c_int
def callback(info, size, data):
# simple search
if data in info.contents.dlpi_name:
print(info.contents.dlpi_name)
return 0
if __name__ == '__main__':
# the target lib we want to find
target_lib = find_library('xml2')
print(target_lib)
# load it
lib = CDLL(target_lib)
# iterate over the loaded libs
dl_iterate_phdr(callback_t(callback), target_lib)
例如:
$ python test.py
libxml2.so.2
/usr/lib/libxml2.so.2
$
关于python - 在 Python 中使用 ctypes.util.find_library 获取库的完整路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22579308/
这has been asked on SO before甚至还有 a related bug on this in CMAKE .但是,我的问题是变体,答案不明确。 我的问题是我正在使用 MinGW
一指定find_library( name PATHS path1..pathn) 我的问题是如何find_library()将名称与库文件匹配(在 Windows 和 Linux 上)? 例如,我无
CMake的find_library如何处理“libFOO.so.3.2”中的版本号?有些库有从 libFOO.so 到正确版本的符号链接(symbolic link),有些则没有。 当我只使用 fi
在我的项目中,我使用了 differend 3rd 库,这些库已经预先构建并添加到 external-debs 子目录中。我使用多个 FindXXX CMake 脚本来定位这些需求。 当我尝试定位 F
我想出了以下 super 简单的 FindMAGMA.cmake 脚本来查找 MAGMA 库,因为周围没有: # - Find the MAGMA library # # Usage: # fin
是否可以调试find_library来自 CMake? 我想要的是经过考虑的路径列表。我的用例是一个像 find_library (FOO_LIBRARY NAMES fo
我的目标是通过 CMake 链接库/usr/lib/libboinc_api.a 和/usr/lib/libboinc.a。因此,我使用不同 FIND_XXXX 模块中给出的示例并尝试: FI
我目前正在创建一组应该在 使用 CLion 的不同项目。我的问题是如何实现这个 功能。 到目前为止,我研究了以下相关问题 这并没有真正解决我的问题: CMake link to external li
在我的 CMake 脚本中,我必须链接到一个库,该库可以有两个不同的名称,具体取决于缓存变量。 库可以是 libMyLibrary.a 或 libMyLibraryCUDA.a,具体取决于 CUDA_
我正在尝试使用来自 ctypes 的命令 find_library() 但我收到一个错误,我不明白它的原因。我在 Windows 上工作 这是代码: import ctypes from ctypes
我目前正在尝试让 CMake 为我的项目运行(在 Windows 上)。我想使用安装所有库的自定义位置。为了让 CMake 知道这条路径,我尝试这样做: set(CMAKE_PREFIX_PATH D
我正在使用 CMake 2.8.2版本。该项目使用了大量外部文件和自定义库(无法通过 find_package 获得),并且有一长串元素,如下所示: find_path(XXX_INCLUDE_DIR
在 cmake 的 find_library 函数的文档中,我们有 The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more dire
这个问题在这里已经有了答案: How to strip trailing whitespace in CMake variable? (4 个回答) 4年前关闭。 我的 CMakeLists.txt
尽管阅读了文档,但我无法弄清楚 CMake 的命令是否为 find_library是否搜索 LD_LIBRARY_PATH 中列出的目录。 我的测试给出了不同的结果。 最佳答案 来自文档(我没有转载与
我用了 list存储库的名称,我想使用 foreach和 find_library找到每个库的完整路径。但是find_library刚刚返回第一个库的路径。我查了 this post ,但问题依然存在
我有一个名为 mylib 的 catkin 库,我用 catkin build 构建了它此外,我有一个节点,其中使用了该库中的函数。我像往常一样在节点的 CMakeLists.txt 中启用此链接:
我在默认安装了 glew 1.10 的 Ubuntu 14.04 上。我想使用最新的 glew 1.13,但是 sudo apt-get remove libglew1.10 不是一个选项,因为 ub
我正在尝试学习 CMake。我有《掌握 CMake》一书,我正在尝试完成我的第一个“简单”教程。 Using CMake: Hello World Example 我顺利地完成了第一部分,但是当我尝试
[注意:这几乎是 Linking to a library that hasn't been built yet with CMake 的副本, 但在这种情况下,未构建的库来自 ADD_CUSTOM_
我是一名优秀的程序员,十分优秀!