我想使用https://github.com/openjdk/jextract工具为/usr/include/yara.h
头文件生成Java绑定。
来自自述文件:
jextract jextract是一个从本地库头文件机械地生成Java绑定的工具。这个工具利用clangC API来解析与给定本地库相关的头文件。生成的Java绑定构建在Foreign Function & Memory API上。jextract工具最初是在Project Panama的上下文中开发的(然后在Project Panama Early Access二进制文件中提供)。
我能够构建和测试项目,但在运行以下命令时,intmax_t
的类型定义出现了一些问题:
build/jextract/bin/jextract --source --output java-yara --target-package com.virustotal.yara /usr/include/yara.h
/usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'
I checked the /usr/include/inttypes.h
file and it correctly imports the <stdint.h> header:
/*
* ISO C99: 7.8 Format conversion of integer types <inttypes.h>
*/
#ifndef _INTTYPES_H
#define _INTTYPES_H 1
#include <features.h>
/* Get the type definitions. */
#include <stdint.h>
这里https://github.com/MaurizioCasciano/jextract/tree/unknown_type_name_intmax_t是我的fork,使用简单的Taskfile构建项目并重现运行时的错误:
task build
task yara-extract
而不是完整的命令,如果你愿意。
我也尝试过添加相关的include路径,但没有成功。
-I /usr/include
-I /usr/include/yara
-I /usr/lib/llvm-15/lib/clang/15.0.6/include
我还遗漏了什么东西来允许将这个typedef解析为'intmax_t'
?
下面你可以看到我使用的工具。
- 环境**
$ hostnamectl
Operating System: Ubuntu 22.04.1 LTS
Kernel: Linux 5.15.0-52-generic
Architecture: x86-64
$ java --version
openjdk 19 2022-09-20
OpenJDK Runtime Environment (build 19+36-2238)
OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)
$ gradle --version
------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------
Build time: 2022-11-25 13:35:10 UTC
Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 19 (Oracle Corporation 19+36-2238)
OS: Linux 5.15.0-52-generic amd64
$ llvm-config-15 --version
15.0.6
$ clang-15 --version
Ubuntu clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
我还能够解析/usr/include/yara.h
头文件以生成相应的**抽象语法树(AST)**代码表示:
clang-15 -fsyntax-only -Xclang -ast-dump /usr/include/yara.h | grep intmax_t
并正确返回引用:
|-TypedefDecl 0x559220f80400 <line:72:1, col:18> col:18 referenced __intmax_t 'long'
|-TypedefDecl 0x559220f80470 <line:73:1, col:27> col:27 referenced __uintmax_t 'unsigned long'
|-TypedefDecl 0x55922102e2f0 <line:101:1, col:21> col:21 referenced intmax_t '__intmax_t':'long'
| `-TypedefType 0x55922102e2c0 '__intmax_t' sugar
| |-Typedef 0x559220f80400 '__intmax_t'
|-TypedefDecl 0x55922102e380 <line:102:1, col:22> col:22 referenced uintmax_t '__uintmax_t':'unsigned long'
| `-TypedefType 0x55922102e350 '__uintmax_t' sugar
| |-Typedef 0x559220f80470 '__uintmax_t'
|-FunctionDecl 0x55922102e788 <line:290:1, col:74> col:17 imaxabs 'intmax_t (intmax_t)' extern
| |-ParmVarDecl 0x55922102e6c0 <col:26, col:35> col:35 __n 'intmax_t':'long'
|-FunctionDecl 0x55922102ea68 <line:293:1, line:294:41> line:293:18 imaxdiv 'imaxdiv_t (intmax_t, intmax_t)' extern
| |-ParmVarDecl 0x55922102e8e0 <col:27, col:36> col:36 __numer 'intmax_t':'long'
| |-ParmVarDecl 0x55922102e958 <col:45, col:54> col:54 __denom 'intmax_t':'long'
|-FunctionDecl 0x559221040998 <line:297:1, /usr/include/x86_64-linux-gnu/sys/cdefs.h:79:54> /usr/include/inttypes.h:297:17 strtoimax 'intmax_t (const char *restrict, char **restrict, int)' extern
|-FunctionDecl 0x559221040cc8 </usr/include/inttypes.h:301:1, /usr/include/x86_64-linux-gnu/sys/cdefs.h:79:54> /usr/include/inttypes.h:301:18 strtoumax 'uintmax_t (const char *restrict, char **restrict, int)' extern
|-FunctionDecl 0x5592210410e8 </usr/include/inttypes.h:305:1, /usr/include/x86_64-linux-gnu/sys/cdefs.h:79:54> /usr/include/inttypes.h:305:17 wcstoimax 'intmax_t (const __gwchar_t *restrict, __gwchar_t **restrict, int)' extern
|-FunctionDecl 0x559221041428 </usr/include/inttypes.h:310:1, /usr/include/x86_64-linux-gnu/sys/cdefs.h:79:54> /usr/include/inttypes.h:310:18 wcstoumax 'uintmax_t (const __gwchar_t *restrict, __gwchar_t **restrict, int)' extern
1条答案
按热度按时间waxmsbnn1#
正如@ JornVernee所建议的,此问题与使用https://apt.llvm.org/上提供的APT包在Ubuntu上安装LLVM和CLang有关
我使用GitHub上的最新版本存档进行了测试,没有任何问题:
对于跳过的long double本机类型,只有一些警告。
这是
Taskfile.yaml
,用于下载和解压缩LLVM+CLang
归档文件,并在一个简单的Maven模块结构中生成YARA-Java
绑定: