3

我想使用 Project Panama 的jextract工具来构建与 Rust 库的 Java 绑定。运行以下命令时,出现错误:

jextract -C -x -C c++ -I /Library/Developer/CommandLineTools/usr/include/c++/v1 -t adder -o adder.jar bindings.h
java.lang.RuntimeException: /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:93:15: fatal error: 'stdlib.h' file not found

我很困惑,因为包含路径包含stdlib.h

ls /Library/Developer/CommandLineTools/usr/include/c++/v1/ | grep stdlib                                        
cstdlib
stdlib.h

错误行仅包含#include_next <stdlib.h>.

我的 Rust 源代码是一个简单的函数:

#[no_mangle]
pub extern "C" fn addition(a: u32, b: u32) -> u32 {
    a + b
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn adds() {
        assert_eq!(addition(1, 2), 3);
    }
}

bindings.h头由cbindgencrate 生成:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>

extern "C" {

uint32_t addition(uint32_t a, uint32_t b);

} // extern "C"

我需要做什么jextract才能找到stdlib.h

4

1 回答 1

2

这是缺少包含路径的情况 - 我还需要包含 MacOS SDK stdlib.h 头文件位置。从错误中并不清楚这一点。

运行的正确命令是:

jextract -C -x -C c++ -I /Library/Developer/CommandLineTools/usr/include/c++/v1 -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -t adder -o adder.jar bindings.h
于 2020-07-07T14:34:49.760 回答