【问题标题】:Fatal error "'stdlib.h' file not found" when running jextract on the C binding for a Rust project在 Rust 项目的 C 绑定上运行 jextract 时出现致命错误“'stdlib.h' 文件未找到”
【发布时间】:2020-07-07 13:20:39
【问题描述】:

我想使用 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 标头由 cbindgen crate 生成:

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

extern "C" {

uint32_t addition(uint32_t a, uint32_t b);

} // extern "C"

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

【问题讨论】:

  • 这和Java有什么关系?
  • 这不是通过与您之前的问题“cstdarg file not found” when running jextract on the C binding for a Rust project 相同的技术解决的吗?您是否要为项目中的每个唯一标头提出相同的问题?请edit您的问题故意链接到您之前的问题,并澄清这个问题的不同之处。
  • 我不是。当我发布时,我认为这是一个不同的问题。进一步研究后,它大致相似。
  • @NomadMaker 这是 OpenJDK Project Panama。 jextract 工具由 JDK 提供。
  • 不知道为什么这个问题被否决了,但是这个问题的解决方案帮助我解决了一个问题。继续问!

标签: java rust ffi project-panama


【解决方案1】:

这是缺少包含路径的情况 - 我还需要包含 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

【讨论】:

  • 我在本地构建了 LLVM,但遇到了这个错误(上周运行良好)。添加-I /Library/Developer/CommandLineTools/usr/include/c++/v1 -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include 使其工作,
猜你喜欢
  • 2018-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多