4

I want to use Project Panama's jextract tool to build a Java binding to a Rust library. When running the following command, I get an error:

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

I'm confused because the include path contains stdlib.h:

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

The line in error contains only #include_next <stdlib.h>.

My Rust source is a simple function:

#[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);
    }
}

The bindings.h header is generated by the cbindgen crate:

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

extern "C" {

uint32_t addition(uint32_t a, uint32_t b);

} // extern "C"

What do I need to do for jextract to locate stdlib.h?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
junglie85
  • 1,243
  • 10
  • 30
  • What does this have to do with Java? – NomadMaker Jul 07 '20 at 13:40
  • Is this not solved by the same techniques as your previous question [“cstdarg file not found” when running jextract on the C binding for a Rust project](https://stackoverflow.com/q/62760145/155423)? Are you going to ask the same question for each unique header in your project? Please [edit] your question to deliberately link to your previous question and clarify how this question differs. – Shepmaster Jul 07 '20 at 13:40
  • I'm not. I thought it was a different issue when I posted. Having looked into it some more, it's broadly similar. – junglie85 Jul 07 '20 at 14:19
  • 1
    @NomadMaker this is OpenJDK [Project Panama](https://openjdk.java.net/projects/panama/). The jextract tool is provided by the JDK. – junglie85 Jul 07 '20 at 14:20
  • Jextract is a tool. If you're using a drill, do you include the "steel" and "plastic" tags because the drill is made of steel and plastic? – NomadMaker Jul 07 '20 at 14:21
  • @NomadMaker perhaps you could propose a more appropriate set of tags that the OP should have used instead? You can probably even do so in an [edit]. – Shepmaster Jul 07 '20 at 14:28
  • 1
    No idea why this question was voted down, but the solution to this question helped me fix a problem. Keep asking! – Galder Zamarreño Sep 03 '20 at 15:54

1 Answers1

3

This was a case of missing an include path - I needed to include the MacOS SDK stdlib.h header file location also. This wasn't clear from the error.

The correct command to have run was:

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
junglie85
  • 1,243
  • 10
  • 30
  • I had built LLVM locally and was getting this error (having worked fine last week). Adding `-I /Library/Developer/CommandLineTools/usr/include/c++/v1 -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include` made it work, – Galder Zamarreño Sep 03 '20 at 15:55