Python ctypes - 在头文件中调用静态内联函数?

标签 python c static inline ctypes

我正在使用 Python 的 ctypes 调用 Linux 上的英特尔处理器跟踪库 (libipt)。库中的初始化函数之一 pt_config_init() 在 intel-pt.h 头文件中被定义为静态内联函数。当我尝试从我的 Python 代码中调用此函数时,它会抛出此错误:

  libipt.pt_config_init(byref(config))
File "/usr/lib64/python3.5/ctypes/__init__.py", line 355, in __getattr__
  func = self.__getitem__(name)
File "/usr/lib64/python3.5/ctypes/__init__.py", line 360, in __getitem__
  func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /lib64/libipt.so.1.4.0: undefined symbol: pt_config_init

这是有道理的,因为函数没有编译到库中,而是通过在相关 C 源代码中包含头文件来访问。有没有办法用 ctypes 调用这样的内联函数,如果可以,如何调用?如果没有,有什么建议的解决方法吗?

最佳答案

不,这不可能。

这个函数不仅没有被你的库导出,它根本不存在!

当编译器决定它值得内联时(关键字只是建议) 函数体被复制/粘贴到所有未定义内联时通常会被调用的地方。

关于Python ctypes - 在头文件中调用静态内联函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40517532/

相关文章:

python : Correct way to strip <p> and </p> from string?

python - DataFrame 列将字典列表存储为字符串 : Parse it and build a new dataframe

ios - UIAlertView 未从辅助类中显示

Java静态方法内存分配

python - Google云平台上的Hadoop集群无法启动

python - StreamingHttpResponse : return database connection to pool/close it

c - 在没有cmd.exe弹出窗口的情况下使用C中的popen在Windows上执行任务列表

c++ - 使用 Eclipse 的 RSE 插件更新远程文件

C编程中的编译器错误 "void value not ignored as it ought to be"

c - 让 gcc 内联并导出函数