有C函数签名数据库吗?

问题描述 投票:0回答:1

查看 MicroHs 源代码,它列出了 C 函数及其签名,以便它们可以在 Haskell 的 FFI 中使用:

 * The types are
 *   V    void    name(void)
 *   i    int     name(void)
 *   I    value_t name(voi)
 *   IV   void    name(value_t)
 *   II   value_t name(value_t)
 *   IIV  void    name(value_t, value_t)
 *   III  value_t name(value_t, value_t)
 *   DD   flt_t  name(flt_t)
 *   Pi   int     name(void*)
 *   PI   value_t name(void*)
 *   PP   void*   name(void*)
 *   iPi  int     name(int, void*)
 *   PPI  value_t name(void*, void*)
 *   PPP  void*   name(void*, void*)

然后

  { "log",      (funptr_t)log,     FFI_DD },
  { "exp",      (funptr_t)exp,     FFI_DD },
[...]
  { "fgetc",    (funptr_t)fgetc,   FFI_Pi },
  { "fputc",    (funptr_t)fputc,   FFI_iPi },

我想知道这样的表是否不能自动生成?

C 编译器了解我系统上的 ABI,因此如果它编译了 C 库,它还应该包含有关签名的信息,例如

log
fgetc

我如何自动生成此列表?

c clang interop ffi abi
1个回答
0
投票

我想知道这样的表是否不能自动生成? [...] 我如何自动生成此列表?

您可以查看 PyQt(使用 SIP)和 PySide 如何生成 Python 绑定。

PySide 使用Shiboken。我会专注于此。

C 编译器了解我系统上的 ABI

实际上,Shiboken 使用 clang。您可以使用

运行其测试
PYTHONPATH=$PWD/tests/minimalbinding:$PWD/tests/samplebinding:$PWD/tests/otherbinding:$PWD/tests/smartbinding /usr/bin/ctest --force-new-ctest-process --output-on-failure --stop-on-failure

如果附加

-VV
标志,您可以看到更多输出。

有一个名为

dumpcodemodel
的程序可用于从 C++ 头文件中提取信息:

 % ./tests/dumpcodemodel/dumpcodemodel                                                                                                  
Usage: ./tests/dumpcodemodel/dumpcodemodel [options] argument(s)

Type system dumper

Parses a C++ header and dumps out the classes found in typesystem XML syntax.
Arguments are arguments to the compiler the last of which should be the header
or source file.
It is recommended to create a .hh include file including the desired headers
and pass that along with the required include paths.

Based on Qt 6.4.2 and LibClang v0.62.

Options:
  -h, --help             Displays help on commandline options.
  --help-all             Displays help including Qt specific options.
  -v, --version          Displays version information.
  --verbose              Display verbose output about types
  --debug                Display debug output
  -j, --join-namespaces  Join namespaces
  --std <level>          C++ Language level (c++11..c++20, default=c++17)

Arguments:
  argument               C++ compiler argument

构建 Shiboken 时,请确保您所在的分支与您的 Qt 版本相对应。我使用的是 Debian 11,所以我使用了 Qt 6.4 的分支。请参阅

dpkg -l qt6-base-dev
。否则,它是一个常规的 cmake 构建系统,您可以在其中创建一个单独的构建目录并执行
cmake ..
来执行与
./configure
等效的操作。

© www.soinside.com 2019 - 2024. All rights reserved.